列出在 Git 提交(添加、修改、删除)之间具有更改状态的所有更改文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15271435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:16:42  来源:igfitidea点击:

List all changed files with change status between Git commits (added, modified, deleted)

gitgit-diff

提问by Jon Cram

I regularly use the following command to list files changed between two commits:

我经常使用以下命令来列出两次提交之间更改的文件:

git diff --name-only SHA1 SHA2

It gives a list of files somewhat like this:

它给出了一个文件列表,有点像这样:

/src/example/file1
/src/example/file2
/src/example/file3

There is almost no end to how useful this is.

这几乎是无止境的。

I'd really like to be able also to show alongside each file a brief reference to the change status, indicating whether a file was added, modified or deleted.

我真的很希望能够在每个文件旁边显示一个对更改状态的简要引用,表明文件是否被添加、修改或删除。

Here's an example to demonstrate the concept:

这是一个演示该概念的示例:

git diff --name-only --and-how-me-the-change-status SHA1 SHA2
A /src/example/file1
M /src/example/file2
D /src/example/file3

The change status (A, M, D) is shown as an example only, I don't mind what this is so long as it is unambiguous.

更改状态 (A, M, D) 仅作为示例显示,我不介意这是什么,只要它是明确的。

I'm aware that I can use the --diff-filteroption to list only added files, or only modified files or only deleted files. Using this option means I have to run three commands to get three lists of filenames. This is nice but could be nicer.

我知道我可以使用该--diff-filter选项仅列出添加的文件、仅列出已修改的文件或仅列出已删除的文件。使用这个选项意味着我必须运行三个命令来获取三个文件名列表。这很好,但可以更好。

Is there a single command I can run to give me the above example output?

有没有我可以运行的单个命令来给我上面的示例输出?

回答by Alexander Konstantinov

Use --name-status, it's the same as --name-onlyplus the status of changed files:

使用--name-status, 与--name-onlyplus 更改文件的状态相同:

git diff --name-status SHA1 SHA2