Dan Rosenstark
Dan Rosenstark

Reputation: 69787

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.

Upvotes: 627

Views: 759494

Answers (21)

Naghi
Naghi

Reputation: 169

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"

Upvotes: 2

Hamza Hmem
Hamza Hmem

Reputation: 596

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.

Upvotes: 4

R...
R...

Reputation: 2620

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}

Upvotes: 2

mabiyan
mabiyan

Reputation: 714

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.

Upvotes: 0

Ahmed Bermawy
Ahmed Bermawy

Reputation: 2530

To see the last commit:

git log -1

To see the last 2 commits:

git log -2

And so on ....

Upvotes: 86

Yas
Yas

Reputation: 5481

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

Upvotes: 6

Laurent Pinson
Laurent Pinson

Reputation: 446

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

Upvotes: 0

ADV-IT
ADV-IT

Reputation: 851

To see previous Commit SHA

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

Upvotes: 3

Kiruthika kanagarajan
Kiruthika kanagarajan

Reputation: 954

To Get my last commit message alone in git

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

Upvotes: 5

Riddhi Sanyal
Riddhi Sanyal

Reputation: 473

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.

Upvotes: 14

nickhar
nickhar

Reputation: 20913

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       

Upvotes: 75

Mithilesh Tipkari
Mithilesh Tipkari

Reputation: 737

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.

Upvotes: 27

HadziJo
HadziJo

Reputation: 57

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.

Upvotes: 1

Ismail Cherri
Ismail Cherri

Reputation: 153

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

Upvotes: 5

shubham mishra
shubham mishra

Reputation: 1234

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.

Upvotes: 35

Greg Hewgill
Greg Hewgill

Reputation: 994471

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.

Upvotes: 355

andy magoon
andy magoon

Reputation: 2929

git diff --stat HEAD

This shows the same diffstat as your last commit.

Upvotes: 6

Mike Seplowitz
Mike Seplowitz

Reputation: 10385

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.

Upvotes: 565

micrub
micrub

Reputation: 738

git log -1 --name-status

Does the work for me.

Upvotes: 23

knittl
knittl

Reputation: 265807

git log -1 --stat

could work

Upvotes: 169

Greg Bacon
Greg Bacon

Reputation: 139681

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

or

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

Upvotes: 13

Related Questions