Search code examples
gitgit-diff

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


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?


Solution

  • 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.