從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