如何在git的检出后挂钩中找出哪些文件已更改? [英] How can I find out what files have changed in the post-checkout hook in git?

查看:85
本文介绍了如何在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(可能已更改,也可能未更改)的引用,以及
  • 一个标志,指示签出是分支签出(更改分支,flag=1)还是文件签出(从索引,flag=0中检索文件).
  • 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).

在您的情况下,您的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:

git show --pretty="" --name-only HEAD

由于尚未更改分支,因此即使所有文件都已签出,该标志也将设置为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'.
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 来列出存在的文件在结帐之前.

If you need a list of files reset by a 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.

这篇关于如何在git的检出后挂钩中找出哪些文件已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆