636

I just want to see the files that were committed in the last commit exactly as I saw the list when I did git commit. Unfortunately searching for

git "last commit" log 

in Google gets me nowhere. And

git diff HEAD^..HEAD 

is not what I need, of course, since it spews the guts of the change too.

3
  • 56
    Thanks, I actually just needed git diff HEAD^..HEAD! Commented Feb 18, 2014 at 9:57
  • 3
    @Ameen faster to type with git show -1 Commented Jun 6, 2021 at 6:30
  • @Ameen Also git diff HEAD^ HEAD Commented Mar 5, 2024 at 16:58

21 Answers 21

577

As determined via comments, it appears that the OP is looking for

$ git log --name-status HEAD^..HEAD 

This is also very close to the output you'd get from svn status or svn log -v, which many people coming from subversion to git are familiar with.

--name-status is the key here; as noted by other folks in this question, you can use git log -1, git show, and git diff to get the same sort of output. Personally, I tend to use git show <rev> when looking at individual revisions.

Sign up to request clarification or add additional context in comments.

7 Comments

I think this gives THE last commit, no? So, for MY last I would do git log --stat --author nroose -n 1
And can be abbreviated and shortened with git show --name-status --oneline
In the case of using force push this comand will show you the last patch instead of the latest (timewise) commit ... might be tricky in some use cases
Shown nothing to me :-(
just use -1 for the last commit instead of HEAD^...HEAD.
|
361

Use git show:

git show --summary 

This will show the names of created or removed files, but not the names of changed files. The git show command supports a wide variety of output formats that show various types of information about commits.

6 Comments

@jamessan git show --stat is close, but isn't there a view where the word 'modified' or 'added' appears next to the file?
If you want just the names of the files (even less than --stat), you may also want to look at --name-status and --name-only switches.
@MikeSep, that's actually what I needed. If you make it an answer I'll mark it best answer, since to me it was. I'm using git log --name-status HEAD^..HEAD
This is by far the simplest solution of the ones offered.
If you just call git show, you will see a diff of your last commit
|
170
git log -1 --stat 

could work

3 Comments

Other solutions seems to output uncommited changes in addition to the last commit, which is not what I want. This seems to output only the commit changes.
you can put -2 to show two last commits or any number to show that number of last commits eg: git log -2 --stat
The behavior of this seems to be identical to git show --stat
89

To see the last commit:

git log -1 

To see the last 2 commits:

git log -2 

And so on ....

3 Comments

But the question said "...want to see the files that were committed in the last commit".
I know this discussion was ages ago, but listen @PeterMortensen if --name-status option added $ git log -1 --name-status then it's same as $ git log --name-status HEAD^..HEAD suggested by @Mike Seplowitz
This was perfect for me since in my case, I only wanted to get my hands on the commit hashes and didn't need any of the other info. This only displays is the commit hash, author, and date - starting with the most recent. Nice and succinct.
76

By far the simplest command for this is:

git show --name-only 

As it lists just the files in the last commit and doesn't give you the entire guts

An example of the output being:

commit fkh889hiuhb069e44254b4925d2b580a602 Author: Kylo Ren <[email protected]> Date: Sat May 4 16:50:32 2168 -0700 Changed shield frequencies to prevent Millennium Falcon landing www/controllers/landing_ba_controller.js www/controllers/landing_b_controller.js www/controllers/landing_bp_controller.js www/controllers/landing_h_controller.js www/controllers/landing_w_controller.js www/htdocs/robots.txt www/htdocs/templates/shields_FAQ.html 

5 Comments

Consider --name-status instead of --name-only.
There's the problem right there.. the empire's using php for the defence grid!
Best example I've seen on stackoverflow! "Those aren't the commits you're looking for."
For those coming along after, if you look at the edits made on 2020-01-14, the other comments will make more sense. Well, except the first one, which already made sense.
If you still want the status but also want the shortened form, consider git show --oneline --name-status.
35

To see last commit changes

git show HEAD 

Or to see second last commit changes

git show HEAD~1 

And for further just replace '1' in above with the required commit sequence number.

Comments

27

After you do several commits or clone/pull a repository, you might want to see what commits have been made. Just check these simple solutions to see your commit history (from last/recent commit to the first one).

For the last commit, just fire this command: git log -1. For more interesting things see below -

  1. To see the commit ID (SHA-1 checksum), Author name <mail ID>, Date along with time, and commit message -

    git log 
  2. To see some more stats, such as the names of all the files changed during that commit and number of insertions/deletions. This comes in very handy while reviewing the code -

    git log --stat 
  3. To see commit histories in some pretty formats :) (This is followed by some prebuild options)-

    • If you have too many commits to review, this command will show them in a neat single line:

      git log --pretty=oneline 
    • To see short, medium, full, or even more details of your commit, use following, respectively -

      git log --pretty=short git log --pretty=medium git log --pretty=full git log --pretty=fuller 
  4. You can even use your own output format using the format option -

    git log --pretty=format:"%an, %ae - %s" 

    where %an - author name, %ae - author email, %s - subject of commit, etc.

This can help you with your commit histories. For more information, click here.

Comments

23
git log -1 --name-status 

Does the work for me.

Comments

15

This question is already answered above which states the file names in last commit by git log / other commands. If someone wants to see what all changed in last commit (line differences), you can use this command -

git show 

This automatically displays the line differences in last commit.

Comments

13
$ git diff --name-only HEAD^..HEAD

or

$ git log --name-only HEAD^..HEAD

4 Comments

That's what I need pretty much. How about something saying whether it was modified, added or deleted? Maybe with a letter, svn-style?
Got it now. git log --name-status HEAD^..HEAD
Instead of git log ... HEAD^..HEAD, isn't it simpler to use git log ... -1 HEAD, or better git show ... HEAD?
After browsing through a couple of Stackoverflow posts, this is the answer I need. I only wanted the files and nothing else. No commit summary, just the files from the latest commit. THANKS!
7

Like git log -1 --stat you can use git show --stat.

Comments

6

git diff --stat HEAD

This shows the same diffstat as your last commit.

Comments

6

You can run

git show --source 

it shows the author, Date, the commit's message and the diff --git for all changed files in latest commit.

Comments

5

Another way to list only the files is to use:
git diff-tree --no-commit-id --name-only -r HEAD^..HEAD
Or you can use any two commit IDs

2 Comments

advantages of this to log?
It is basically a different way of listing the files. I usually combine this with rsync for deployment
5

To Get my last commit message alone in git

git log --format=%B -n 1 $(git log -1 --pretty=format:"%h") | cat -

Comments

3

To see previous Commit SHA

git log -n 2 --pretty=format:"%h" | tail -n 1 

Comments

2

if you want to see just the name of files in the last commit

git diff HEAD@{1} --name-only 

if you want also to see the content changes remove the --name-only

if you want to compare current state with older commits, increase the {n}

Comments

2

From man git-diff, then typing /EXAMPLES:

 git diff HEAD^ HEAD 

Compare the version before the last commit and the last commit.

Comparing with arbitrary commits

 git diff test (1) git diff HEAD -- ./test (2) 
  1. Instead of using the tip of the current branch, compare with the tip of "test" branch.
  2. Instead of comparing with the tip of "test" branch, compare with the tip of the current branch, but limit the comparison to the file "test".

General use

 git diff (1) git diff --cached (2) git diff HEAD (3) 
  1. Changes in the working tree not yet staged for the next commit.

  2. Changes between the index and your last commit; what you would be committing if you run "git commit" without "-a" option.

  3. Changes in the working tree since your last commit; what you would be committing if you run "git commit -a"

Comments

1

If you're talking about finding the latest and greatest commit after you've performed a git checkout of some earlier commit (and forgot to write down HEAD's hash prior to executing the checkout) most of the above won't get you back to where you started. git log -[some #] only shows the log from the CURRENT position of HEAD, which is not necessarily the very last commit (state of the project). Checkout will disconnect the HEAD and point it to whatever you checked out.

You could view the entire git reflog, until reaching the entry referencing the original clone. BTW, this too won't work if any commits were made between the time you cloned the project and when you performed a checkout. Otherwise you can hope all your commits on your local machine are on the server, and then re-clone the entire project.

Hope this helps.

1 Comment

Thanks, it’s a good point but the original question was much simpler and already answered well many times.
0

and without git: tail -n1 .git/logs/HEAD | cut -d' ' -f1,8-

Comments

0

First run below command to get your commitId and copy the commitId of which you want to see the files for.

git log 

Then run,

git show <commitId> --name-only 

In the above command replace with actual commitid you got from git log. Hope this helps someone.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.