Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git archive在具有不同提交日期的文件中显示相同的提交日期_Git_Git Archive - Fatal编程技术网

git archive在具有不同提交日期的文件中显示相同的提交日期

git archive在具有不同提交日期的文件中显示相同的提交日期,git,git-archive,Git,Git Archive,在git中,我有两个提交日期不同的文件。但是,当我制作git归档文件时,我得到了相同的提交日期,为什么 [[ -e git_test ]] && rm -rf git_test mkdir git_test cd git_test git init # make file01 echo 'f01 $Format:%cd$' > file01.txt echo 'file01.txt export-subst' >> .gitattributes git add

在git中,我有两个提交日期不同的文件。但是,当我制作
git归档文件时,我得到了相同的提交日期,为什么

[[ -e git_test ]] && rm -rf git_test
mkdir git_test
cd git_test
git init

# make file01
echo 'f01 $Format:%cd$' > file01.txt
echo 'file01.txt export-subst' >> .gitattributes
git add .gitattributes file01.txt
git commit -m "adding file01"
sleep 1
# make file02
echo 'f02 $Format:%cd$' > file02.txt
echo 'file02.txt export-subst' >> .gitattributes
git add .gitattributes file02.txt
git commit -m "adding file02"

# git archive
git archive HEAD | tar -x -C ..

echo
echo "git log date"
git log --format="%cd" file01.txt
git log --format="%cd" file02.txt

echo
echo "git archive date"
cd ..
cat *.txt
在输出中,使用
git log
提交日期不同(1秒),但使用
git archive
生成的文件具有相同的提交日期

git log date
Fri Dec 27 15:17:22 2013 -0300
Fri Dec 27 15:17:23 2013 -0300

git archive date
f01 Fri Dec 27 15:17:23 2013 -0300
f02 Fri Dec 27 15:17:23 2013 -0300

git archive期间关键字替换中使用的提交日期是您正在导出的提交日期,即15:17:23的第二次提交日期。Git不会找到涉及特定文件的最新提交并获取其提交日期。这就是当您运行例如
git log--format=“%cd”file01.txt
(它将列出所有涉及该文件的提交日期,但在本例中只有一个提交)。

我仅在最后修改的文件中使用
归档解决了这个问题

 git archive HEAD $(git diff --name-only HEAD^) | tar -x -C
这种方式仅修改上次修改的文件的提交日期(和文件)