Finding diff between current and last version
Using Git, how can you find the difference between the current and the last version?
git diff last version:HEAD
I don't really understand the meaning of "last version".
As the previous commit can be accessed with HEAD^, I think that you are looking for something like:
git diff HEAD^ HEAD
That also can be applied for a :commithash
git diff $commithash^ $commithash
As of Git 1.8.5, @
is an alias for HEAD
, so you can use:
git diff @~..@
The following will also work:
git show
If you want to know the diff between head and any commit you can use:
git diff commit_id HEAD
And this will launch your visual diff tool (if configured):
git difftool HEAD^ HEAD
Since comparison to HEAD is default you can omit it (as pointed out by Orient):
git diff @^
git diff HEAD^
git diff commit_id
Warnings
- @ScottF and @Panzercrisis explain in the comments that on Windows the
~
character must be used instead of^
.
Assuming "current version" is the working directory (uncommitted modifications) and "last version" is HEAD
(last committed modifications for the current branch), simply do
git diff HEAD
Credit for the following goes to user Cerran
.
And if you always skip the staging area with -a
when you commit, then you can simply use git diff
.
Summary
-
git diff
shows unstaged changes. -
git diff --cached
shows staged changes. -
git diff HEAD
shows all changes (both staged and unstaged).
Source: git-diff(1) Manual Page – Cerran