Git: See my last commit
GitGit Problem Overview
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.
Git Solutions
Solution 1 - Git
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.
Solution 2 - Git
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.
Solution 3 - Git
git log -1 --stat
could work
Solution 4 - Git
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
Solution 5 - Git
To see last commit
git log -1
To see last 2 commit
git log -2
etc....
Solution 6 - Git
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.
Solution 7 - Git
git log -1 --name-status
Does the work for me.
Solution 8 - Git
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 -
-
To see the commit ID (SHA-1 checksum), Author name <mail ID>, Date along with time, and commit message -
git log
-
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
-
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
-
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][1].
[1]: https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History "More on viewing commit history"
Solution 9 - Git
$ git diff --name-only HEAD^..HEAD
or
$ git log --name-only HEAD^..HEAD
Solution 10 - Git
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.
Solution 11 - Git
git diff --stat HEAD
This shows the same diffstat as your last commit.
Solution 12 - Git
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
Solution 13 - Git
To Get my last commit message alone in git
git log --format=%B -n 1 $(git log -1 --pretty=format:"%h") | cat -
Solution 14 - Git
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.
Solution 15 - Git
To see previous Commit SHA
git log -n 2 --pretty=format:"%h" | tail -n 1
Solution 16 - Git
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.
Solution 17 - Git
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}
Solution 18 - Git
and without git: tail -n1 .git/logs/HEAD | cut -d' ' -f1,8-
Solution 19 - Git
Like git log -1 --stat
you can use git show --stat
.