588

I would like to do a diff between two tags and committed changes between those two tags. Could you please tell me the command?

0

5 Answers 5

987
$ git diff tag1 tag2

or show log between them:

$ git log tag1..tag2

sometimes it may be convenient to see only the list of files that were changed:

$ git diff tag1 tag2 --stat

and then look at the differences for some particular file:

$ git diff tag1 tag2 -- some/file/name

A tag is only a reference to the latest commit 'on that tag', so that you are doing a diff on the commits between them.

(Make sure to do git pull --tags first)

Also, a good reference: https://git-scm.com/docs/git-diff

12
  • 2
    @kaiser lol! btw, I would like to add this tip to compare whole directories from within git gui at "tools/add" like git difftool -d $REVISION! and to link this answer too Commented Jun 20, 2014 at 6:09
  • Is there a way to make the git log command only show additional commits, not shared commits? Commented Dec 28, 2015 at 8:48
  • @CMCDragonkai that is what this command does, it shows the additional commits on tag2 since tag1.
    – gauteh
    Commented Dec 28, 2015 at 16:27
  • 2
    Also useful: simply git diff tag1 gives differences between tag1 and working directory; git diff tag1 HEAD differences between tag1 and most recent commit.
    – ChrisV
    Commented Mar 24, 2016 at 15:59
  • 1
    If the tag names aren't pulled locally the diff command will fail. For me pull tags didnt get all the tags I needed. So manually pull the two tags locally then running the git diff tab b while having tag a checkout worked
    – Norbert
    Commented May 6 at 20:28
16

If source code is on Github, you can use their comparing tool: https://help.github.com/articles/comparing-commits-across-time/

1
  • 1
    is there any way to do this without the 250 commit limit? Commented Dec 28, 2020 at 15:35
7

For a side-by-side visual representation, I use git difftool with openDiff set to the default viewer.

Example usage:

git difftool tags/<FIRST TAG> tags/<SECOND TAG>

If you are only interested in a specific file, you can use:

git difftool tags/<FIRST TAG>:<FILE PATH> tags/<SECOND TAG>:<FILE PATH>

As a side-note, the tags/<TAG>s can be replaced with <BRANCH>es if you are interested in diffing branches.

2

As @Nakilon said, their is a comparing tool built in github if that's what you use.

To use it, append the url of the repo with "/compare".

1
  • 1
    is there any way to do this without the 250 commit limit? Commented Dec 28, 2020 at 15:34
1

Number of insertions/deletions between 2 tags (combine all commits between tags, for example, 1 file was changed/committed 6 times between tags)

git log --numstat --format='' v1.0..v1.1 | awk '{files += 1}{ins += $1}{del += $2} END{print "total: "files" files, "ins" insertions(+) "del" deletions(-)"}'
total: 6 files, 57 insertions(+) 12 deletions(-)

diff between tags, for example, diff of the same file at tag v1.0 and at v1.1

 git diff --shortstat v1.0 v1.1
 1 file changed, 50 insertions(+), 5 deletions(-)

Just to show that stats for diff (kind of similar to vimdiff), and for all commits in between are different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.