[git] Git: See my last commit

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.

This question is related to git

The answer is


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.


To see last commit

git log -1

To see last 2 commit

git log -2

etc....


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.


git diff --stat HEAD

This shows the same diffstat as your last commit.


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       

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


git log -1 --name-status

Does the work for me.


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.


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.


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

or

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

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.


git log -1 --stat

could work


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.