Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding diff between current and last version

Tags:

git

Using Git, how can you find the difference between the current and the last version?

git diff last version:HEAD 
like image 373
Rajeev Avatar asked Mar 28 '12 08:03

Rajeev


People also ask

How can I see the last commit of a diff?

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.

How do I see changes in current commit?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command.

How do you find the difference between two commits?

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..

What is a git diff?

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.


2 Answers

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 ^.
like image 107
Francisco Puga Avatar answered Oct 02 '22 22:10

Francisco Puga


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

  1. git diff shows unstaged changes.
  2. git diff --cached shows staged changes.
  3. git diff HEAD shows all changes (both staged and unstaged).

Source: git-diff(1) Manual Page – Cerran

like image 35
CharlesB Avatar answered Oct 02 '22 23:10

CharlesB