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

Time:09-21

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?

CodePudding user response:

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.

CodePudding user response:

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 @~ @
  • Related