Using Git, how can you find the difference between the current and the last version?
git diff last version:HEAD
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.
Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command.
To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..
Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.
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
~
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With