获取特定 Git 提交的已更改文件列表及其状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24803627/
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
Get a list of changed files and their status for a specific Git commit
提问by Ashraf Bashir
I use the following Git command
我使用以下 Git 命令
git diff-tree --no-commit-id --name-only -r <SHA>
to get a list of changed files.
获取已更改文件的列表。
Unfortunately, the list doesn't specify the type of change for each file: added, modified or deleted ... etc
不幸的是,该列表没有指定每个文件的更改类型:添加、修改或删除......等
How may I display a list of changes [type of change, file name] in a given SHA of a specific commit.
如何在特定提交的给定 SHA 中显示更改列表 [更改类型、文件名]。
回答by Joe
Use --name-status
instead of --name-only
使用--name-status
代替--name-only
git diff-tree --no-commit-id --name-status -r <SHA>
This will show the filename with a status letter of (extracted from man): Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B).
这将显示带有状态字母的文件名(从 man 中提取): Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B).
回答by Ashraf Bashir
While Joe's answerpoints out that you can use the --name-status
flag with git diff-tree
, you can also use the same flag with git diff
instead.
虽然Joe 的回答指出您可以使用--name-status
with 标志git diff-tree
,但您也可以使用相同的标志 with git diff
。
To get the changed files with their status for just a specific commit, you can just use the sha id of that commit with a commit-parent specifier, like so
要获取更改的文件及其特定提交的状态,您可以使用该提交的 sha id 和 commit-parent 说明符,就像这样
git diff --name-status <sha>^ <sha>
The revision specifier <sha>^
means the first parent of the commit <sha>
, so using that with git diff
effectively gives you all the changes that were made between a commit and its parent.
修订说明符<sha>^
表示 commit 的第一个父级<sha>
,因此使用 withgit diff
有效地为您提供在提交与其父级之间所做的所有更改。
Alternative
选择
You can also use
你也可以使用
git diff --name-status <sha>~ <sha>
where <sha>~
also means the first parent of commit <sha>
.
其中<sha>~
也表示 commit 的第一个父级<sha>
。
Documentation
文档
回答by Ashraf Bashir
Thanks to hvd's commenton stdcall's answer,
Your original answer, which included the
git whatchanged SHA-1
form, was almost right: add the-1
option to get only that specific commit.
您的原始答案(包括
git whatchanged SHA-1
表单)几乎是正确的:添加-1
仅获取该特定提交的选项。
here is the solution for those who are interested:
以下是有兴趣的人的解决方案:
git whatchanged <SHA> -1
Another solution is:
另一种解决方案是:
git diff-tree --no-commit-id -r <SHA>
回答by stdcall
Use
用
git whatchanged
to see the last commit
查看最后一次提交
回答by Martin G
git checkout <commit>
git whatchanged -1