10

I find myself typing this pretty often, like when I made some change, committed it, and then either need to look up something I did there to figure out what to do next, or make sure I didn't add anything unintended to the commit before pushing it to a remote.

Admittedly, diff HEAD^ HEAD is fast enough to type (git diTABHTAB^ HTAB), but it still feels like there should be a better way.

How do I easiest see all changes made in the last commit?

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319

5 Answers5

14

Try git show. Without other options, it shows a diff of the latest commit.

git show $something shows the content of $something in a user-friendly way. When $something refers to a file, git show will display the file's content. When it refers to a commit, Git shows the commit (author, date, commit log and diff). git show without more arguments is equivalent to git show HEAD.

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
  • Brilliant! Could you also explain why `show` does this? I normally use that to display entire files at some revision; would never have though that it shows a diff when given no arguments. – leftaroundabout Mar 07 '16 at 13:05
  • @leftaroundabout `git show ` will display the log message and the textual diff of the given commit. If not commit id is given, HEAD is used. – Frodon Mar 07 '16 at 13:09
9

I also found in this post that @ is a shortcut for HEAD. So

git diff @^ @

or

git show @

is also an option.

Community
  • 1
  • 1
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
5

You can use one of the following:

(Choose the one which suits you and make it an alias).

# the equivalent command (dry run) for pull/push
git log ^branch1 branch2
git log branch1 ^branch 2

git show

# to view the content of the last commit
git show

Shows one or more objects (blobs, trees, tags and commits).

For commits it shows the log message and textual diff. It also presents the merge commit in a special format as produced by git diff-tree --cc.


git log --cc

From git v>2.6 you have the --cc flag added to the log so you can use

git log --cc

It will display the full log with the diff as well.

enter image description here


git diff-tree --cc HEAD

Very similar to the git log --cc. Behind the scenes git show is an alias to this command.

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I'll probably use mostly the simple `git show`, but nice to know about `log --cc` too. Could come handy when I need to know about the last _three_ commits or so. – leftaroundabout Mar 07 '16 at 13:16
0

A pretty sweet way would be to use an alias. Sure, it's a quick fix but

$> alias gd="diff HEAD^ HEAD" 

would do the trick. Now you can use:

$> gd

and your command would be run.

Add the alias command to your ~/.bashrc, or likewise, and you don't have to write it in the beginning of each console session.

fgummesson
  • 31
  • 5
0

Info: The shortest syntax using git diff seems like:

git diff @^!

i.e. git diff HEAD^!

Or use the shortest git show as mentioned.

For syntax meaning, see https://git-scm.com/docs/gitrevisions#_other_rev_parent_shorthand_notations for r1^!

Johnny Wong
  • 945
  • 9
  • 16