git 如何查看上次提交中更改了哪些文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49853177/
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
How to see which files were changed in last commit
提问by Sahand
In this commit message, it says that 2 files have been changed.
在此提交消息中,它说 2 个文件已更改。
$ git commit -m "fixed .gitignore"
[master c30afbe] fixed .gitignore
Committer: Sahand Zarrinkoub <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
2 files changed, 5 insertions(+), 4 deletions(-)
This is a little surprising for me. I thought I'd only staged one file to be changed. Now, I'd like to see which files have been changed and how. What is the way to do this?
这对我来说有点令人惊讶。我以为我只会上演一个要更改的文件。现在,我想看看哪些文件已被更改以及如何更改。有什么方法可以做到这一点?
回答by Robin He
Get all changed files since last commit
获取自上次提交以来所有更改的文件
git diff --name-only HEAD HEAD~1
回答by Nitin Bisht
You can use git log --stat
您可以使用 git log --stat
Here --stat
will display the number of insertions and deletions to each file altered by each commit.
这里--stat
将显示每次提交更改的每个文件的插入和删除次数。
Example:Below commit added 67 lines to the Demo.java
file and removed 38 lines:
示例:下面的提交向Demo.java
文件添加了 67 行并删除了 38 行:
commit f2a238924456ca1d4947662928218a06d39068c3
Author: X <[email protected]>
Date: Fri May 21 15:17:28 2020 -0500
Add a new feature
Demo.java | 105 ++++++++++++++++++++++++-----------------
1 file changed, 67 insertion(+), 38 deletions(-)
回答by Andrejs Cainikovs
You can do this in a number of ways. This is what I came up with without looking into docs.
您可以通过多种方式执行此操作。这是我在没有查看文档的情况下想到的。
$ git log -1 --name-only
commit 3c60430b752bca26bd3c80604df87ffb2ae358 (HEAD -> master, origin/master, origin/HEAD)
Author: Name Surname <[email protected]>
Date: Mon Apr 2 18:17:25 2018 +0200
Example commit
.gitignore
README
src/main.c
Or:
或者:
$ git log -1 --name-only --oneline
commit 3c60430 (HEAD -> master, origin/master, origin/HEAD) Example commit
.gitignore
README
src/main.c
Or:
或者:
$ git log -1 --stat --oneline
commit 3c60430 (HEAD -> master, origin/master, origin/HEAD) Example commit
.gitignore | 2 ++
README | 8 ++++++++
src/main.c | 12 ++++++++++++
3 files changed, 22 insertions(+)
回答by Andrejs Cainikovs
git log // this will give you the hash-code
git show hash-code
回答by sprutex
In addition to Nitin Bisht's answer you can use the following:
除了 Nitin Bisht 的回答之外,您还可以使用以下内容:
git log -1 --stat --oneline
It will show condensed information on which files were changed in last commit. Naturally, instead of "-1" there can by any number of commits specified to show files changed in last "-n" commits.
它将显示有关在上次提交中更改了哪些文件的简要信息。自然地,可以指定任意数量的提交而不是“-1”来显示在最后“-n”提交中更改的文件。
Also you can skip merged commits passing "--no-merges" flag:
您也可以跳过传递“--no-merges”标志的合并提交:
git log -1 --stat --oneline --no-merges
回答by Jesferman
git diff-tree --no-commit-id --name-only <commit_hash>
git diff-tree --no-commit-id --name-only <commit_hash>