leftaroundabout
leftaroundabout

Reputation: 120751

Is the a shorter way of writing git diff HEAD^ HEAD?

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?

Upvotes: 10

Views: 1650

Answers (5)

Johnny Wong
Johnny Wong

Reputation: 975

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^!

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 142532

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

Upvotes: 5

fgummesson
fgummesson

Reputation: 31

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.

Upvotes: 0

leftaroundabout
leftaroundabout

Reputation: 120751

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

git diff @^ @

or

git show @

is also an option.

Upvotes: 9

nwellnhof
nwellnhof

Reputation: 33658

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.

Upvotes: 15

Related Questions