Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell git to show diff of changes I did in last commit? [duplicate]

Tags:

git

git-diff

With git, how do I see the changes in my last commit?

I mean I want to see a diff between my last commit and the commit previous to it. I know that I can see it on Github browser but I want to see this on terminal on my local commit history.

I know that I can do git diff between commits. So, I can do git diff oldCommit...HEAD to see the changes. But is there a command which can prevent me from having to copy oldCommit from git log which is cumbersome?

like image 824
TheWaterProgrammer Avatar asked Dec 05 '25 06:12

TheWaterProgrammer


2 Answers

There are a few ways to see that, but the simplest is probably just:

git show

The git show command displays a formatted version of an object it git's database. Without any arguments, it shows HEAD - the currently checked out commit.

For a commit, its default output is the commit message and a diff to that commit's first parent - you can tweak that with the --format option.

like image 115
IMSoP Avatar answered Dec 07 '25 20:12

IMSoP


Your most recent commit is HEAD, also known as @. The commit before anything is that thing suffixed with ~1 or simply ~. So you could say

git diff @~ @
like image 43
matt Avatar answered Dec 07 '25 20:12

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!