签入后更新ident字符串

时间:2012-11-19 13:30:21

标签: git ident

我已在$Id:$文件中通过ident扩展了.gitattributes。这样,当其他人签出我的存储库并从那里安装文件时,我可以快速识别文件是否过时。

现在,我还将自己的Git存储库的内容同步到其他(非开发,即没有Git)系统。问题是关键字扩展只发生在 checkout 上,但我的工作流程是 commit - >推 - >同步,因此同步的副本包含过时的ID。

如何在本地提交后轻松强制更新ID? (任何提交后自动执行此操作的奖励积分!)

简单的git checkout不起作用(也不适用于--force),可能是因为文件内容没有改变。 git checkout-index --force也没有。我只是通过本地修改(繁琐,需要知道修改过的文件)来实现这一目的:

$ echo "modified" >> file
$ git checkout file

或暂时检查以前的提交:

$ git checkout HEAD^
$ git checkout HEAD@{1}

3 个答案:

答案 0 :(得分:1)

这里有一些建议:

git checkout --force .git checkout --force file.txt

如果其中一个命令有效,那么你可以创建一个脚本.git/hooks/post-commit并让该脚本成为调用该命令的一行代码(或任何命令可以工作),然后git将在每次提交时执行此操作。我相信钩子脚本自动将工作directy的根目录(.git文件夹所在的位置)设置为脚本的cwd。

编辑:

如果您运行touch file.txt; git checkout file.txt,那么git将执行完整的检出,包括在我测试时应用ident属性。希望可以某种方式使用

答案 1 :(得分:0)

这可以通过post-commit钩子完成。我通过脚本自动完成设置,该脚本是git-extensions repository

的一部分
$ git-ident-update --help
Update the expansion of $Id$ to $Id:...$ via ident in the .gitattributes
after a commit.
To do this automatically in the future, invoke with --install.
Usage: git-ident-update [--install|--uninstall|--status|--set [<path>[ <path> ...]]] [-?|-h|--help]

答案 2 :(得分:0)

我使用以下命令对其中包含git ID的最近更新的文件运行touch和git checkout:

find . -type f -mtime -1 -a -not -name '*~' | \
   xargs grep -l '$Id:' | \
   xargs --replace --verbose sh -c '{ touch {} ; git checkout {}; }'