git diff $(git log --pretty=format:%h -2 --reverse | tr "\n" " ")

Git diff last two commits

A great command to assign to an alias, allowing you to git diff the last two commits in git.

1
2015-07-07 17:50:50

These Might Interest You


  • 0
    git diff --name-only --diff-filter=AMXTCR HEAD~2 HEAD | xargs -l -I{} cp --parents --verbose "{}" target_dir
    batandwa · 2013-02-11 08:12:40 0

  • 1
    git log -p -z | perl -ln0e 'print if /[+-].*searchedstring/'
    takeshin · 2010-06-13 07:41:22 0
  • Use this to make a new commit that "softly" reverts a branch to some commit (i.e. squashes the history into an inverse patch). You can review the changes first by doing the diff alone.


    4
    git diff HEAD..rev | git apply --index; git commit
    Pistos · 2009-02-06 17:29:46 0
  • This form is used in patches, svn, git etc. And I've created an alias for it: alias diff='diff -Naur --strip-trailing-cr' The latter option is especially useful, when somebody in team works in Windows; could be also used in commands like svn diff --diff-cmd 'diff --strip-trailing-cr'... Show Sample Output


    3
    diff -Naur --strip-trailing-cr
    ruslan · 2011-02-10 14:32:42 0
  • get subversion diff output without distracting whitespace changes. good for when you are cleaning up code to make sure you didn't change anything important. also useful when working with old code, or someone else's code.


    0
    svn diff --diff-cmd diff -x -uw /path/to/file
    katylava · 2009-02-10 20:39:54 1
  • My script lists all users & the number of commits they made in the period, sorted alphabetically. To sort by number of commits, append a '|sort' to the end of the command. The script depends on the output format of svn log - original command didn't work for me because the string 'user' was not appearing in my output


    0
    svn log -r{2011-08-01}:HEAD|awk '$14 ~/line/ {print $3}'|sort|uniq -c
    sangnoir · 2011-09-01 07:58:54 0

What Others Think

Isn't that the same as: git diff HEAD~1 HEAD and if there aren't any local changes, it's the same as: git diff HEAD~1
flatcap · 149 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: