从git hooks --help
:
post-checkout
This hook is invoked when a git checkout is run after having updated
the worktree. The hook is given three parameters: the ref of the
previous HEAD, the ref of the new HEAD (which may or may not have
changed), and a flag indicating whether the checkout was a branch
checkout (changing branches, flag=1) or a file checkout (retrieving a
file from the index, flag=0). This hook cannot affect the outcome of
git checkout.
所以你可以有一个后结账挂钩,可以在工作树中所有具有特定扩展名的文件上运行,并在其上调用SetFile
。这并不完美,因为它会重新对未更改的文件执行操作,并且在git reset --hard
之后完全不会运行,但可能满足您的需要。
一结账后挂机,将名为*.txt
的所有文件(但没有其他人)这样做是很简单的:
#! /bin/sh
git ls-files -z -- '*.txt' | xargs -0 SetFile -t TEXT
的-z
和-0
做这项工作的硬壳路径名(包含嵌入式的人例如空间)。
torek,非常感谢。我将您的代码完全粘贴到您提交的结账后,并且第一次运行! – wscole 2012-04-09 20:18:44