有人知道如何将添加/更新文件的 mtime 更改为存储库提交时间(或任何其他时间,但取决于提交元数据)?
我们有一些逻辑,可以测试文件的 mtime,但是后端服务器对已更改的文件有不同的 mtime,因此我们有一些错误。
最佳答案
假设您在执行 git fetch
时要更新/添加文件,您可以创建一个 git-rebase-and-touch 脚本文件,该文件会为您执行 rebase 操作,并触摸每个新版本中的所有文件/目录。
脚本看起来像:
#!/bin/bash
saveIFS=${IFS}
IFS=$'\n'
startrev=$(git rev-parse HEAD)
git rebase
for rev in $(git rev-list --reverse ${startrev}..HEAD); do
stamp=$(git log --pretty="%aD" ${rev}~..${rev})
IFS=$'\n'
for filename in $(git diff --name-only ${rev}~..${rev}); do
file=""
IFS='/'
for part in ${filename}; do
file=${file}/${part}
file=${file#/}
touch -c --date="${stamp}" "${file}"
done
done
done
IFS=${saveIFS}
如果您当前使用 git pull
,请改用 git fetch
。
关于linux - 更改 git pull 上的 mtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19070541/