Reputation: 8370
In this commit message, it says that 2 files have been changed.
$ 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?
Upvotes: 129
Views: 120855
Reputation: 256
The OP asked "Now, I'd like to see which files have been changed and how".
git log -p -1
will do this.
It will show the files changed, and their diff.
commit 688459646aa8f32a8xxxxxxxxxxxxee9034e91 (HEAD -> test)
Author: xxx <[email protected]>
Date: Tue Jan 2 20:52:14 2024 -0500
Relative output needs relative input
diff --git a/internal/adapter/handlebars/handlebars_test.go b/internal/adapter/handlebars/handlebars_test.go
index 6a942c0..373cd7a 100644
--- a/internal/adapter/handlebars/handlebars_test.go
+++ b/internal/adapter/handlebars/handlebars_test.go
@@ -238,6 +238,8 @@ func TestFormatDateHelper(t *testing.T) {
testString(t, "{{format-date now 'timestamp'}}", context, "200911172034")
testString(t, "{{format-date now 'timestamp-unix'}}", context, "1258490098")
testString(t, "{{format-date now 'cust: %Y-%m'}}", context, "cust: 2009-11")
+ year := time.Now().UTC().Year() - 14
+ context = map[string]interface{}{"now": time.Date(year, 11, 17, 20, 34, 58, 651387237, time.UTC)}
testString(t, "{{format-date now 'elapsed'}}", context, "14 years ago")
}
Upvotes: 1
Reputation: 1084
Using diff-tree
git diff-tree --no-commit-id --name-only -r <commit_hash>
Upvotes: 8
Reputation: 307
git show --name-only
This is simplest form. It is the similar to git show
(which shows the diff of the last commit), except it shows the filenames that were changed, instead of the diff.
Upvotes: 0
Reputation: 3419
Get all changed files in the last commit
git diff --name-only HEAD HEAD~1
Upvotes: 235
Reputation: 28474
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(+)
Or (thanks to Bencho Naut):
$ git log -1 --name-only --pretty=''
.gitignore
README
src/main.c
Upvotes: 36
Reputation: 30297
This is the preferred one for me
git show --name-status --pretty=""
Or if I only want the names of the files:
git show --name-only --pretty=""
Other things like --stat
are also available with git show
.
Upvotes: 0
Reputation: 5361
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 <[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(-)
Upvotes: 162
Reputation: 1440
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
Upvotes: 13