git-提交中所有已更改但未删除的文件的列表 [英] git - list of all changed but not deleted files in a commit

查看:55
本文介绍了git-提交中所有已更改但未删除的文件的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查git存储库.我想获取每次提交中已更改文件的列表.

I am investigating git repositories. I want to get the list of changed files in each commit.

所以,我要做的是我通过命令访问了每个提交

So, what I did is I visited each commit through the command

git reset --hard <commitId>

然后,我用

git show --pretty="format:" --name-only #{commitId}

这一问题的原因是它在我不需要的commitId中提供了已删除的文件.我也尝试过:

The problem with this one is that it gives the deleted files in that commitId which I don't want. I tried also:

git ls-files 

它不返回已删除的文件,但是,它返回所有新文件或在先前提交中创建的所有现有文件的列表.

it doesn't return deleted files, however, it returns a list of all existing files that are new or were created in previous commit.

示例:

>commit 1
add "file1"
add "file2"

>commit 2
change "file1"

>commit 3
add "file3"
delete "file2"

因此,在这种情况下,我将访问每个提交.而且,如果我正在提交1,我想获取"file1"和"file2"的列表.如果我在提交2中,则将得到"file1",如果我在提交3中,则将得到"file3".

so in this case, I will visit each commit. And, if I am in commit 1, I want to get a list of "file1" and "file2". If I am in commit 2, I will get "file1", and "file3" if I am in commit 3.

有什么想法吗?

推荐答案

尝试使用此命令:

git show --diff-filter=AM --pretty="format:" --name-only #{commitId}

这是您在原始问题中提到的内容,其中添加了-diff-filter 标志,以仅限制已添加( A )或已修改( M ).有关可以限制的文件类型的完整列表,请查看 git的文档.显示.

It is what you mentioned in your original problem with a --diff-filter flag added to restrict to only files which were added (A) or modified (M). For a complete list of the types of files to which you can restrict, have a look at the documentation for git show.

正如@MauricioTrajano在他的回答中提到的那样,您无需重置为提交即可使用 git show 进行调查.您只需要知道提交的SHA-1哈希即可,只需在相关分支上使用 git log 即可找到它.

As @MauricioTrajano mentioned in his answer, you don't need to reset to a commit to investigate it using git show. All you need to know is the SHA-1 hash of the commit, which you can find by simply using git log on the branch in question.

这篇关于git-提交中所有已更改但未删除的文件的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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