如何在git的检出后挂钩中找出哪些文件已更改? [英] How can I find out what files have changed in the post-checkout hook in git?
问题描述
我只是git的新手,我正在查看结帐后的钩子.
据我了解,以下命令将从最新提交中恢复文件名":
I'm only new to git and I'm looking at the post-checkout hook.
As I understand it the following command will restore "filename" from the latest commit:
git checkout -- filename
在结帐后获得控制权时,我得到3个参数,即2个SHA和一个类型.
两个SHA都相同,即上一次提交和类型的SHA的值均为0,这表示已签出文件.
但是在家里,我能找出什么文件被检出吗?
When I get control in post-checkout I get 3 arguments, namely 2 SHAs and a type.
Both the SHAs are the same, namely the SHA of the last commit and type has a value of 0 which means a checkout of a file occurred.
But home do I find out what file was checked out?
推荐答案
该挂钩具有三个参数:
The hook is given three parameters: 在您的情况下,您的HEAD并未更改.您可能已将一些修改后的文件初始化回HEAD内容,但除此之外,所有已签出的文件仍会签出: In your case, your HEAD has not changed. You might have some modified files initialized back to the HEAD content, but other than that, all files already checked out are still checked out: 由于尚未更改分支,因此即使所有文件都已签出,该标志也将设置为0.因此,没有简单的方法来查看哪些内容已被修改并重置为HEAD内容. Since you have not changed branches, the flag is set to 0, even if all files were already checked out. So there is no easy way to see which ones were modified and reset to HEAD content. 关键是:结帐后挂钩不能影响'git checkout'的结果. The key is: that post-checkout hook cannot affect the outcome of 'git checkout'. 如果需要由 If you need a list of files reset by a 这篇关于如何在git的检出后挂钩中找出哪些文件已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
flag=1
)还是文件签出(从索引,flag=0
中检索文件).
flag=1
) or a file checkout (retrieving a file from the index, flag=0
).git show --pretty="" --name-only HEAD
换句话说,索引和工作树已经反映了它们的最终状态(并且不记得以前发生了什么)
On other words, the index and working tree already reflect their final state (and don't remember what was there before)git checkout .
重置的文件列表,最好首先执行git stash
.
然后git checkout
:您的检出后挂钩可以使用git stash show
来列出存在的文件在结帐之前.git checkout .
, it is best to do first a git stash
.
Then a git checkout
: your post-checkout hook can then use git stash show
in order to list the files that were present before the checkout.