Git: See my last commit

Viewed 555541

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.

19 Answers

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.

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.

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

or

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

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.

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

To Get my last commit message alone in git

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

To see previous Commit SHA

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

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.

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}

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.

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

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

Related