How to see which files were changed in last commit
GitGit Problem Overview
In this commit message, it says that 2 files have been changed.
$ 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(-)
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?
Git Solutions
Solution 1 - Git
Get all changed files since last commit
git diff --name-only HEAD HEAD~1
Solution 2 - Git
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(-)
Solution 3 - Git
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(+)
Solution 4 - Git
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
Solution 5 - Git
git log // this will give you the hash-code
git show hash-code
Solution 6 - Git
git diff-tree --no-commit-id --name-only <commit_hash>