How to see the changes between two commits without commits in-between?

How do you make git diff only show the difference between two commits, excluding the other commits in-between?

  • git-svn fetch isn't pulling in the latest versions
  • Changes to main branch not appearing after merging
  • Is it possible to directly install a gem from a git repository?
  • Suddenly every git command causes `error: bad signature` in every Git repository
  • Execute child process in Node which takes control of the console
  • How can I add a folder outside of my working directory to the Git repository?
  • Manually merge git pull request
  • Git rename from index.lock to index failed
  • git showing branches that are not on github anymore
  • How can I discard modified files?
  • Accidentally branched off of the wrong branch, and when I want to merge into the master I have to merge both branches
  • git push origin master: permission denied (public key) error
  • 8 Solutions collect form web for “How to see the changes between two commits without commits in-between?”

    you can simply pass the 2 commits to git diff like :

    -> git diff 0da94be  59ff30c > my.patch
    -> git apply my.patch
    

    Asking for the difference /between/ two commits without including the commits in-between makes little sense. Commits are just snapshots of the contents of the repository; asking for the difference between two necessarily includes them. So the question then is, what are you really looking for?

    As William suggested, cherry-picking can give you the delta of a single commit rebased on top of another. That is:

    $ git checkout 012345
    $ git cherry-pick -n abcdef
    $ git diff --cached
    

    This takes commit ‘abcdef’, compares it to its immediate ancestor, then applies that difference on top of ‘012345’. This new difference is then shown – the only change is the context comes from ‘012345’ rather than ‘abcdef’s immediate ancestor. Of course, you may get conflicts and etc, so it’s not a very useful process in most cases.

    If you’re just interested in abcdef itself, you can do:

    $ git log -u -1 abcdef
    

    This compares abcdef to its immediate ancestor, alone, and is usually what you want.

    And of course

    $ git diff 012345..abcdef
    

    gives you all differences between those two commits.

    It would help to get a better idea of what you’re trying to achieve – as I mentioned, asking for the difference between two commits without what’s in between doesn’t actually make sense.

    To compare two git commits 12345 and abcdef as patches one can use the diff command as

    diff <(git show 123456) <(git show abcdef)
    
    git diff <a-commit> <another-commit> path
    

    Example:

    git diff commit1 commit2 config/routes.rb
    

    It shows the difference on that file between those commits.

    Suppose you want to see the difference between commits 012345 and abcdef. The following should do what you want:

    $ git checkout 012345
    $ git cherry-pick -n abcdef
    $ git diff --cached
    

    Let’s say you have this

    A
    |
    B    A0
    |    |
    C    D
    \   /
      |
     ...
    

    And you want to make sure that A is the same as A0.

    This will do the trick:

    $ git diff B A > B-A.diff
    $ git diff D A0 > D-A0.diff
    $ diff B-A.diff D-A0.diff
    

    What about this:

    git diff abcdef 123456 | less
    

    It’s handy to just pipe it to less if you want to compare many different diffs on the fly.

    Actually I haven’t found a really good solution for this to do automatically, but a hacky solution that gives you exactly what you want is this;

    1. make a copy of the source directory (copy dir A to dir A-copy),
    2. use git to checkout revision (with force option) of that old commit you want to start with,
    3. copy those backed up files into original (copy dir A-copy onto dir A, except for .git hidden files).
    4. the diff to commit now will include all your changes summed up over all the commits in-between.
    Git Baby is a git and github fan, let's start git clone.