如何查看在上次提交中更改了哪些文件

在这个提交消息中,它说有2个文件已经被更改。

$ git commit -m "fixed .gitignore"
[master c30afbe] fixed .gitignore
Committer: Sahand Zarrinkoub <sahandzarrinkoub@n133-p41.eduroam.kth.se>
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(-)

这对我来说有点意外。我以为我只伪造了一份需要修改的文件。现在,我想看看哪些文件被更改了,以及如何更改的。有什么办法吗?

77384 次浏览
git log  // this will give you the hash-code
git show hash-code

git diff-tree --no-commit-id --name-only <commit_hash>

You can try git log --stat

Here --stat will display the number of insertions and deletions to each file altered by each commit.

Example: Below commit added 67 lines to the Demo.java file and removed 38 lines:

commit f2a238924456ca1d4947662928218a06d39068c3
Author: X <X@example.com>
Date: Fri May 21 15:17:28 2020 -0500
Add a new feature
Demo.java | 105 ++++++++++++++++++++++++-----------------
1 file changed, 67 insertion(+), 38 deletions(-)

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 <name.surname@email.com>
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(+)

Get all changed files since last commit

git diff --name-only HEAD HEAD~1

In addition to Nitin Bisht's answer you can use the following:

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.

Also you can skip merged commits passing "--no-merges" flag:

git log -1 --stat --oneline --no-merges