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












534














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










share|improve this question




















  • 14




    "git diff" always show the difference between two commits (or commit and working directory, etc.).
    – Jakub Narębski
    Jul 28 '09 at 6:48






  • 12




    @JakubNarębski, he is asking how to see the difference between the changes introduced by one command and the changes introduced by another commit. In other words, the diff of diffs or interdiff.
    – psusi
    Sep 4 '15 at 17:50










  • and if you add --dirstat=files parameter to the diff command, you will take a very nice screenshot on the exact projects and files that are changed, together with a change percentage. Like this: git diff [commit-number] [commit-number] --dirstat=files
    – Óscar Ibáñez Fernández
    Jan 3 '17 at 14:53


















534














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










share|improve this question




















  • 14




    "git diff" always show the difference between two commits (or commit and working directory, etc.).
    – Jakub Narębski
    Jul 28 '09 at 6:48






  • 12




    @JakubNarębski, he is asking how to see the difference between the changes introduced by one command and the changes introduced by another commit. In other words, the diff of diffs or interdiff.
    – psusi
    Sep 4 '15 at 17:50










  • and if you add --dirstat=files parameter to the diff command, you will take a very nice screenshot on the exact projects and files that are changed, together with a change percentage. Like this: git diff [commit-number] [commit-number] --dirstat=files
    – Óscar Ibáñez Fernández
    Jan 3 '17 at 14:53
















534












534








534


88





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










share|improve this question















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







git diff






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 3 '17 at 16:40









Vadim Kotov

4,31153247




4,31153247










asked Jul 28 '09 at 0:02







user146069















  • 14




    "git diff" always show the difference between two commits (or commit and working directory, etc.).
    – Jakub Narębski
    Jul 28 '09 at 6:48






  • 12




    @JakubNarębski, he is asking how to see the difference between the changes introduced by one command and the changes introduced by another commit. In other words, the diff of diffs or interdiff.
    – psusi
    Sep 4 '15 at 17:50










  • and if you add --dirstat=files parameter to the diff command, you will take a very nice screenshot on the exact projects and files that are changed, together with a change percentage. Like this: git diff [commit-number] [commit-number] --dirstat=files
    – Óscar Ibáñez Fernández
    Jan 3 '17 at 14:53
















  • 14




    "git diff" always show the difference between two commits (or commit and working directory, etc.).
    – Jakub Narębski
    Jul 28 '09 at 6:48






  • 12




    @JakubNarębski, he is asking how to see the difference between the changes introduced by one command and the changes introduced by another commit. In other words, the diff of diffs or interdiff.
    – psusi
    Sep 4 '15 at 17:50










  • and if you add --dirstat=files parameter to the diff command, you will take a very nice screenshot on the exact projects and files that are changed, together with a change percentage. Like this: git diff [commit-number] [commit-number] --dirstat=files
    – Óscar Ibáñez Fernández
    Jan 3 '17 at 14:53










14




14




"git diff" always show the difference between two commits (or commit and working directory, etc.).
– Jakub Narębski
Jul 28 '09 at 6:48




"git diff" always show the difference between two commits (or commit and working directory, etc.).
– Jakub Narębski
Jul 28 '09 at 6:48




12




12




@JakubNarębski, he is asking how to see the difference between the changes introduced by one command and the changes introduced by another commit. In other words, the diff of diffs or interdiff.
– psusi
Sep 4 '15 at 17:50




@JakubNarębski, he is asking how to see the difference between the changes introduced by one command and the changes introduced by another commit. In other words, the diff of diffs or interdiff.
– psusi
Sep 4 '15 at 17:50












and if you add --dirstat=files parameter to the diff command, you will take a very nice screenshot on the exact projects and files that are changed, together with a change percentage. Like this: git diff [commit-number] [commit-number] --dirstat=files
– Óscar Ibáñez Fernández
Jan 3 '17 at 14:53






and if you add --dirstat=files parameter to the diff command, you will take a very nice screenshot on the exact projects and files that are changed, together with a change percentage. Like this: git diff [commit-number] [commit-number] --dirstat=files
– Óscar Ibáñez Fernández
Jan 3 '17 at 14:53














10 Answers
10






active

oldest

votes


















518














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



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





share|improve this answer



















  • 1




    That worked for me, but now, How can I apply my.patch to other branch?
    – nacho4d
    Jun 2 '11 at 2:53






  • 2




    patch -p1 < my.patch
    – OneOfOne
    Jun 2 '11 at 17:09






  • 2




    @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
    – Felix Rabe
    Feb 3 '12 at 19:49






  • 39




    Thank you. git diff old_commit_hash new_commit_hash works!
    – Maksim Dmitriev
    Feb 27 '13 at 19:00






  • 27




    This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
    – psusi
    Sep 4 '15 at 17:51



















117














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.






share|improve this answer

















  • 23




    I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
    – Chris Cleeland
    Aug 22 '12 at 22:10






  • 5




    @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
    – bdonlan
    Aug 23 '12 at 6:41






  • 3




    @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
    – bdonlan
    Aug 24 '12 at 2:44






  • 6




    The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
    – psusi
    Sep 4 '15 at 17:53






  • 2




    Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
    – lefnire
    Feb 26 '16 at 20:23



















66














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



diff <(git show 123456) <(git show abcdef)





share|improve this answer



















  • 5




    Why would you use GNU diff with git?
    – OneOfOne
    Aug 13 '14 at 22:37






  • 5




    @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
    – Menachem
    Dec 9 '15 at 17:39








  • 8




    @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
    – Menachem
    Dec 10 '15 at 21:20






  • 1




    @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
    – OneOfOne
    Dec 11 '15 at 5:24






  • 7




    This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
    – lefnire
    Feb 26 '16 at 19:50



















55














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.






share|improve this answer





























    14














    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





    share|improve this answer

















    • 3




      Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
      – pogosama
      Sep 7 '17 at 10:16





















    10














    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





    share|improve this answer





















    • Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
      – akostadinov
      Aug 15 '13 at 20:16



















    9














    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.






    share|improve this answer





























      1














      My alias settings in ~/.bashrc file for git diff:



      alias gdca='git diff --cached' # diff between your staged file and the last commit
      alias gdcc='git diff HEAD{,^}' # diff between your recent tow commits


      English is not my native language, please excuse typing errors






      share|improve this answer































        0














        I wrote a script which displays diff between two commits, works well on Ubuntu.



        https://gist.github.com/jacobabrahamb4/a60624d6274ece7a0bd2d141b53407bc



        #!/usr/bin/env python
        import sys, subprocess, os

        TOOLS = ['bcompare', 'meld']

        def getTool():
        for tool in TOOLS:
        try:
        out = subprocess.check_output(['which', tool]).strip()
        if tool in out:
        return tool
        except subprocess.CalledProcessError:
        pass
        return None

        def printUsageAndExit():
        print 'Usage: python bdiff.py <project> <commit_one> <commit_two>'
        print 'Example: python bdiff.py <project> 0 1'
        print 'Example: python bdiff.py <project> fhejk7fe d78ewg9we'
        print 'Example: python bdiff.py <project> 0 d78ewg9we'
        sys.exit(0)

        def getCommitIds(name, first, second):
        commit1 = None
        commit2 = None
        try:
        first_index = int(first) - 1
        second_index = int(second) - 1
        if int(first) < 0 or int(second) < 0:
        print "Cannot handle negative values: "
        sys.exit(0)
        logs = subprocess.check_output(['git', '-C', name, 'log', '--oneline', '--reverse']).split('n')
        if first_index >= 0:
        commit1 = logs[first_index].split(' ')[0]
        if second_index >= 0:
        commit2 = logs[second_index].split(' ')[0]
        except ValueError:
        if first != '0':
        commit1 = first
        if second != '0':
        commit2 = second
        return commit1, commit2

        def validateCommitIds(name, commit1, commit2):
        if commit1 == None and commit2 == None:
        print "Nothing to do, exit!"
        return False
        try:
        if commit1 != None:
        subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit1]).strip()
        if commit2 != None:
        subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit2]).strip()
        except subprocess.CalledProcessError:
        return False
        return True

        def cleanup(commit1, commit2):
        subprocess.check_output(['rm', '-rf', '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

        def checkoutCommit(name, commit):
        if commit != None:
        subprocess.check_output(['git', 'clone', name, '/tmp/'+commit])
        subprocess.check_output(['git', '-C', '/tmp/'+commit, 'checkout', commit])
        else:
        subprocess.check_output(['mkdir', '/tmp/0'])

        def compare(tool, commit1, commit2):
        subprocess.check_output([tool, '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

        if __name__=='__main__':
        tool = getTool()
        if tool == None:
        print "No GUI diff tools"
        sys.exit(0)
        if len(sys.argv) != 4:
        printUsageAndExit()

        name, first, second = None, 0, 0
        try:
        name, first, second = sys.argv[1], sys.argv[2], sys.argv[3]
        except IndexError:
        printUsageAndExit()

        commit1, commit2 = getCommitIds(name, first, second)

        if not validateCommitIds(name, commit1, commit2):
        sys.exit(0)

        cleanup(commit1, commit2)
        checkoutCommit(name, commit1)
        checkoutCommit(name, commit2)

        try:
        compare(tool, commit1, commit2)
        except KeyboardInterrupt:
        pass
        finally:
        cleanup(commit1, commit2)
        sys.exit(0)





        share|improve this answer































          0














          Since Git 2.19, you can simply use:



          git range-diff <rev1>...<rev2>






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1191282%2fhow-to-see-the-changes-between-two-commits-without-commits-in-between%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown
























            10 Answers
            10






            active

            oldest

            votes








            10 Answers
            10






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            518














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



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





            share|improve this answer



















            • 1




              That worked for me, but now, How can I apply my.patch to other branch?
              – nacho4d
              Jun 2 '11 at 2:53






            • 2




              patch -p1 < my.patch
              – OneOfOne
              Jun 2 '11 at 17:09






            • 2




              @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
              – Felix Rabe
              Feb 3 '12 at 19:49






            • 39




              Thank you. git diff old_commit_hash new_commit_hash works!
              – Maksim Dmitriev
              Feb 27 '13 at 19:00






            • 27




              This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
              – psusi
              Sep 4 '15 at 17:51
















            518














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



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





            share|improve this answer



















            • 1




              That worked for me, but now, How can I apply my.patch to other branch?
              – nacho4d
              Jun 2 '11 at 2:53






            • 2




              patch -p1 < my.patch
              – OneOfOne
              Jun 2 '11 at 17:09






            • 2




              @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
              – Felix Rabe
              Feb 3 '12 at 19:49






            • 39




              Thank you. git diff old_commit_hash new_commit_hash works!
              – Maksim Dmitriev
              Feb 27 '13 at 19:00






            • 27




              This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
              – psusi
              Sep 4 '15 at 17:51














            518












            518








            518






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



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





            share|improve this answer














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



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






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 10 '13 at 1:59

























            answered Jul 28 '09 at 1:11









            OneOfOne

            59.5k10115137




            59.5k10115137








            • 1




              That worked for me, but now, How can I apply my.patch to other branch?
              – nacho4d
              Jun 2 '11 at 2:53






            • 2




              patch -p1 < my.patch
              – OneOfOne
              Jun 2 '11 at 17:09






            • 2




              @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
              – Felix Rabe
              Feb 3 '12 at 19:49






            • 39




              Thank you. git diff old_commit_hash new_commit_hash works!
              – Maksim Dmitriev
              Feb 27 '13 at 19:00






            • 27




              This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
              – psusi
              Sep 4 '15 at 17:51














            • 1




              That worked for me, but now, How can I apply my.patch to other branch?
              – nacho4d
              Jun 2 '11 at 2:53






            • 2




              patch -p1 < my.patch
              – OneOfOne
              Jun 2 '11 at 17:09






            • 2




              @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
              – Felix Rabe
              Feb 3 '12 at 19:49






            • 39




              Thank you. git diff old_commit_hash new_commit_hash works!
              – Maksim Dmitriev
              Feb 27 '13 at 19:00






            • 27




              This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
              – psusi
              Sep 4 '15 at 17:51








            1




            1




            That worked for me, but now, How can I apply my.patch to other branch?
            – nacho4d
            Jun 2 '11 at 2:53




            That worked for me, but now, How can I apply my.patch to other branch?
            – nacho4d
            Jun 2 '11 at 2:53




            2




            2




            patch -p1 < my.patch
            – OneOfOne
            Jun 2 '11 at 17:09




            patch -p1 < my.patch
            – OneOfOne
            Jun 2 '11 at 17:09




            2




            2




            @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
            – Felix Rabe
            Feb 3 '12 at 19:49




            @nacho4d: git checkout other-branch && git apply my.patch && git add . && git commit -am "Message"
            – Felix Rabe
            Feb 3 '12 at 19:49




            39




            39




            Thank you. git diff old_commit_hash new_commit_hash works!
            – Maksim Dmitriev
            Feb 27 '13 at 19:00




            Thank you. git diff old_commit_hash new_commit_hash works!
            – Maksim Dmitriev
            Feb 27 '13 at 19:00




            27




            27




            This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
            – psusi
            Sep 4 '15 at 17:51




            This answer utterly fails to address the question, so I have no idea why it has so many upvotes. The OP is specifically asking how NOT to get the first command you give, and the second has nothing to do with anything.
            – psusi
            Sep 4 '15 at 17:51













            117














            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.






            share|improve this answer

















            • 23




              I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
              – Chris Cleeland
              Aug 22 '12 at 22:10






            • 5




              @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
              – bdonlan
              Aug 23 '12 at 6:41






            • 3




              @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
              – bdonlan
              Aug 24 '12 at 2:44






            • 6




              The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
              – psusi
              Sep 4 '15 at 17:53






            • 2




              Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
              – lefnire
              Feb 26 '16 at 20:23
















            117














            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.






            share|improve this answer

















            • 23




              I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
              – Chris Cleeland
              Aug 22 '12 at 22:10






            • 5




              @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
              – bdonlan
              Aug 23 '12 at 6:41






            • 3




              @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
              – bdonlan
              Aug 24 '12 at 2:44






            • 6




              The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
              – psusi
              Sep 4 '15 at 17:53






            • 2




              Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
              – lefnire
              Feb 26 '16 at 20:23














            117












            117








            117






            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.






            share|improve this answer












            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 28 '09 at 16:24









            bdonlan

            174k21221299




            174k21221299








            • 23




              I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
              – Chris Cleeland
              Aug 22 '12 at 22:10






            • 5




              @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
              – bdonlan
              Aug 23 '12 at 6:41






            • 3




              @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
              – bdonlan
              Aug 24 '12 at 2:44






            • 6




              The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
              – psusi
              Sep 4 '15 at 17:53






            • 2




              Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
              – lefnire
              Feb 26 '16 at 20:23














            • 23




              I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
              – Chris Cleeland
              Aug 22 '12 at 22:10






            • 5




              @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
              – bdonlan
              Aug 23 '12 at 6:41






            • 3




              @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
              – bdonlan
              Aug 24 '12 at 2:44






            • 6




              The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
              – psusi
              Sep 4 '15 at 17:53






            • 2




              Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
              – lefnire
              Feb 26 '16 at 20:23








            23




            23




            I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
            – Chris Cleeland
            Aug 22 '12 at 22:10




            I will agree that, in general, it doesn't make much sense to compare two commits. But git is really good at not telling you how you should think. Suppose you have two branches, each with distinct commits that look like they are making the same changes to the same sets of files. I would like to be able to use git to tell me if these two patches are the same without having to trust my eyes. I think there IS utility in this.
            – Chris Cleeland
            Aug 22 '12 at 22:10




            5




            5




            @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
            – bdonlan
            Aug 23 '12 at 6:41




            @ChrisCleeland, the interdiff utility can come in handy in that case. Use git diff to get the diff of each commit against its immediate parent, then use interdiff to compare the diffs.
            – bdonlan
            Aug 23 '12 at 6:41




            3




            3




            @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
            – bdonlan
            Aug 24 '12 at 2:44




            @ChrisCleeland, git does not store patches. It stores file contents. It does have a compression scheme that uses deltas, but the delta sources aren't necessarily correlated with the actual history of the files.
            – bdonlan
            Aug 24 '12 at 2:44




            6




            6




            The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
            – psusi
            Sep 4 '15 at 17:53




            The diff between the two commits excluding other commits on their respective branches makes perfect sense: one commit was cherry picked from the other, but may have some subtle differences. You want to see what they are without being cluttered with all of the other unrelated crap that is different between the two branches.
            – psusi
            Sep 4 '15 at 17:53




            2




            2




            Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
            – lefnire
            Feb 26 '16 at 20:23




            Or say you rebase master onto a feature branch, and must resolve conflicts. Afterwards comparing origin/featurebranch#HEAD to local/featurebranch#HEAD can help you ensure you didn't muck anything during conflict-resolution.
            – lefnire
            Feb 26 '16 at 20:23











            66














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



            diff <(git show 123456) <(git show abcdef)





            share|improve this answer



















            • 5




              Why would you use GNU diff with git?
              – OneOfOne
              Aug 13 '14 at 22:37






            • 5




              @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
              – Menachem
              Dec 9 '15 at 17:39








            • 8




              @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
              – Menachem
              Dec 10 '15 at 21:20






            • 1




              @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
              – OneOfOne
              Dec 11 '15 at 5:24






            • 7




              This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
              – lefnire
              Feb 26 '16 at 19:50
















            66














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



            diff <(git show 123456) <(git show abcdef)





            share|improve this answer



















            • 5




              Why would you use GNU diff with git?
              – OneOfOne
              Aug 13 '14 at 22:37






            • 5




              @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
              – Menachem
              Dec 9 '15 at 17:39








            • 8




              @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
              – Menachem
              Dec 10 '15 at 21:20






            • 1




              @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
              – OneOfOne
              Dec 11 '15 at 5:24






            • 7




              This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
              – lefnire
              Feb 26 '16 at 19:50














            66












            66








            66






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



            diff <(git show 123456) <(git show abcdef)





            share|improve this answer














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



            diff <(git show 123456) <(git show abcdef)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 7 '14 at 22:29

























            answered May 7 '14 at 20:21









            plexoos

            88069




            88069








            • 5




              Why would you use GNU diff with git?
              – OneOfOne
              Aug 13 '14 at 22:37






            • 5




              @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
              – Menachem
              Dec 9 '15 at 17:39








            • 8




              @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
              – Menachem
              Dec 10 '15 at 21:20






            • 1




              @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
              – OneOfOne
              Dec 11 '15 at 5:24






            • 7




              This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
              – lefnire
              Feb 26 '16 at 19:50














            • 5




              Why would you use GNU diff with git?
              – OneOfOne
              Aug 13 '14 at 22:37






            • 5




              @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
              – Menachem
              Dec 9 '15 at 17:39








            • 8




              @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
              – Menachem
              Dec 10 '15 at 21:20






            • 1




              @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
              – OneOfOne
              Dec 11 '15 at 5:24






            • 7




              This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
              – lefnire
              Feb 26 '16 at 19:50








            5




            5




            Why would you use GNU diff with git?
            – OneOfOne
            Aug 13 '14 at 22:37




            Why would you use GNU diff with git?
            – OneOfOne
            Aug 13 '14 at 22:37




            5




            5




            @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
            – Menachem
            Dec 9 '15 at 17:39






            @OneOfOne git diff <(git show 123456) <(git show abcdef) doesn't work; diff <(...) <(...) does. (I just tried it).
            – Menachem
            Dec 9 '15 at 17:39






            8




            8




            @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
            – Menachem
            Dec 10 '15 at 21:20




            @OneOfOne That doesn't do the same thing. What you suggested would compare the trees of each commit, showing a single patch. What I (and @plexoos) are doing are comparing two patches, each having been introduced by separate commits - in other words, diffing the output from two diffs. This involves reading and comparing two input streams. diff (GNU, or Unix, diff) can do that, while git diff cannot. Some may wonder why one would want to do that. I am in the middle of doing that right now, cleaning up a merge that went bad.
            – Menachem
            Dec 10 '15 at 21:20




            1




            1




            @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
            – OneOfOne
            Dec 11 '15 at 5:24




            @Menachem ah interesting, thanks for clearing that up, you learn something new every day!
            – OneOfOne
            Dec 11 '15 at 5:24




            7




            7




            This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
            – lefnire
            Feb 26 '16 at 19:50




            This is the correct answer, the others are misunderstanding the question. Thanks @plexoos!
            – lefnire
            Feb 26 '16 at 19:50











            55














            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.






            share|improve this answer


























              55














              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.






              share|improve this answer
























                55












                55








                55






                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 1 '15 at 16:11









                roadev

                712613




                712613























                    14














                    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





                    share|improve this answer

















                    • 3




                      Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
                      – pogosama
                      Sep 7 '17 at 10:16


















                    14














                    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





                    share|improve this answer

















                    • 3




                      Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
                      – pogosama
                      Sep 7 '17 at 10:16
















                    14












                    14








                    14






                    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





                    share|improve this answer












                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 14 '17 at 18:54









                    Juanpa

                    29328




                    29328








                    • 3




                      Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
                      – pogosama
                      Sep 7 '17 at 10:16
















                    • 3




                      Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
                      – pogosama
                      Sep 7 '17 at 10:16










                    3




                    3




                    Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
                    – pogosama
                    Sep 7 '17 at 10:16






                    Can also be shortened as a one-liner just as the answer by @plexoos: diff <(git diff B A) <(git diff D A0) (same result as with git show)
                    – pogosama
                    Sep 7 '17 at 10:16













                    10














                    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





                    share|improve this answer





















                    • Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
                      – akostadinov
                      Aug 15 '13 at 20:16
















                    10














                    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





                    share|improve this answer





















                    • Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
                      – akostadinov
                      Aug 15 '13 at 20:16














                    10












                    10








                    10






                    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





                    share|improve this answer












                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 28 '09 at 16:14









                    William Pursell

                    129k32206236




                    129k32206236












                    • Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
                      – akostadinov
                      Aug 15 '13 at 20:16


















                    • Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
                      – akostadinov
                      Aug 15 '13 at 20:16
















                    Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
                    – akostadinov
                    Aug 15 '13 at 20:16




                    Thanks, that's a good idea to check your result after squashing commits. For example you can checkout your branch with non-squashed commits and cherry pick your squashed commit to see if everything went smooth with the interactive rebase. Additionally when master has went ahead of the branch.
                    – akostadinov
                    Aug 15 '13 at 20:16











                    9














                    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.






                    share|improve this answer


























                      9














                      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.






                      share|improve this answer
























                        9












                        9








                        9






                        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.






                        share|improve this answer












                        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.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jan 5 '17 at 12:53









                        Flow Overstack

                        13714




                        13714























                            1














                            My alias settings in ~/.bashrc file for git diff:



                            alias gdca='git diff --cached' # diff between your staged file and the last commit
                            alias gdcc='git diff HEAD{,^}' # diff between your recent tow commits


                            English is not my native language, please excuse typing errors






                            share|improve this answer




























                              1














                              My alias settings in ~/.bashrc file for git diff:



                              alias gdca='git diff --cached' # diff between your staged file and the last commit
                              alias gdcc='git diff HEAD{,^}' # diff between your recent tow commits


                              English is not my native language, please excuse typing errors






                              share|improve this answer


























                                1












                                1








                                1






                                My alias settings in ~/.bashrc file for git diff:



                                alias gdca='git diff --cached' # diff between your staged file and the last commit
                                alias gdcc='git diff HEAD{,^}' # diff between your recent tow commits


                                English is not my native language, please excuse typing errors






                                share|improve this answer














                                My alias settings in ~/.bashrc file for git diff:



                                alias gdca='git diff --cached' # diff between your staged file and the last commit
                                alias gdcc='git diff HEAD{,^}' # diff between your recent tow commits


                                English is not my native language, please excuse typing errors







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Nov 16 at 2:58

























                                answered Jun 28 at 9:38









                                Jinmiao Luo

                                6915




                                6915























                                    0














                                    I wrote a script which displays diff between two commits, works well on Ubuntu.



                                    https://gist.github.com/jacobabrahamb4/a60624d6274ece7a0bd2d141b53407bc



                                    #!/usr/bin/env python
                                    import sys, subprocess, os

                                    TOOLS = ['bcompare', 'meld']

                                    def getTool():
                                    for tool in TOOLS:
                                    try:
                                    out = subprocess.check_output(['which', tool]).strip()
                                    if tool in out:
                                    return tool
                                    except subprocess.CalledProcessError:
                                    pass
                                    return None

                                    def printUsageAndExit():
                                    print 'Usage: python bdiff.py <project> <commit_one> <commit_two>'
                                    print 'Example: python bdiff.py <project> 0 1'
                                    print 'Example: python bdiff.py <project> fhejk7fe d78ewg9we'
                                    print 'Example: python bdiff.py <project> 0 d78ewg9we'
                                    sys.exit(0)

                                    def getCommitIds(name, first, second):
                                    commit1 = None
                                    commit2 = None
                                    try:
                                    first_index = int(first) - 1
                                    second_index = int(second) - 1
                                    if int(first) < 0 or int(second) < 0:
                                    print "Cannot handle negative values: "
                                    sys.exit(0)
                                    logs = subprocess.check_output(['git', '-C', name, 'log', '--oneline', '--reverse']).split('n')
                                    if first_index >= 0:
                                    commit1 = logs[first_index].split(' ')[0]
                                    if second_index >= 0:
                                    commit2 = logs[second_index].split(' ')[0]
                                    except ValueError:
                                    if first != '0':
                                    commit1 = first
                                    if second != '0':
                                    commit2 = second
                                    return commit1, commit2

                                    def validateCommitIds(name, commit1, commit2):
                                    if commit1 == None and commit2 == None:
                                    print "Nothing to do, exit!"
                                    return False
                                    try:
                                    if commit1 != None:
                                    subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit1]).strip()
                                    if commit2 != None:
                                    subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit2]).strip()
                                    except subprocess.CalledProcessError:
                                    return False
                                    return True

                                    def cleanup(commit1, commit2):
                                    subprocess.check_output(['rm', '-rf', '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                    def checkoutCommit(name, commit):
                                    if commit != None:
                                    subprocess.check_output(['git', 'clone', name, '/tmp/'+commit])
                                    subprocess.check_output(['git', '-C', '/tmp/'+commit, 'checkout', commit])
                                    else:
                                    subprocess.check_output(['mkdir', '/tmp/0'])

                                    def compare(tool, commit1, commit2):
                                    subprocess.check_output([tool, '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                    if __name__=='__main__':
                                    tool = getTool()
                                    if tool == None:
                                    print "No GUI diff tools"
                                    sys.exit(0)
                                    if len(sys.argv) != 4:
                                    printUsageAndExit()

                                    name, first, second = None, 0, 0
                                    try:
                                    name, first, second = sys.argv[1], sys.argv[2], sys.argv[3]
                                    except IndexError:
                                    printUsageAndExit()

                                    commit1, commit2 = getCommitIds(name, first, second)

                                    if not validateCommitIds(name, commit1, commit2):
                                    sys.exit(0)

                                    cleanup(commit1, commit2)
                                    checkoutCommit(name, commit1)
                                    checkoutCommit(name, commit2)

                                    try:
                                    compare(tool, commit1, commit2)
                                    except KeyboardInterrupt:
                                    pass
                                    finally:
                                    cleanup(commit1, commit2)
                                    sys.exit(0)





                                    share|improve this answer




























                                      0














                                      I wrote a script which displays diff between two commits, works well on Ubuntu.



                                      https://gist.github.com/jacobabrahamb4/a60624d6274ece7a0bd2d141b53407bc



                                      #!/usr/bin/env python
                                      import sys, subprocess, os

                                      TOOLS = ['bcompare', 'meld']

                                      def getTool():
                                      for tool in TOOLS:
                                      try:
                                      out = subprocess.check_output(['which', tool]).strip()
                                      if tool in out:
                                      return tool
                                      except subprocess.CalledProcessError:
                                      pass
                                      return None

                                      def printUsageAndExit():
                                      print 'Usage: python bdiff.py <project> <commit_one> <commit_two>'
                                      print 'Example: python bdiff.py <project> 0 1'
                                      print 'Example: python bdiff.py <project> fhejk7fe d78ewg9we'
                                      print 'Example: python bdiff.py <project> 0 d78ewg9we'
                                      sys.exit(0)

                                      def getCommitIds(name, first, second):
                                      commit1 = None
                                      commit2 = None
                                      try:
                                      first_index = int(first) - 1
                                      second_index = int(second) - 1
                                      if int(first) < 0 or int(second) < 0:
                                      print "Cannot handle negative values: "
                                      sys.exit(0)
                                      logs = subprocess.check_output(['git', '-C', name, 'log', '--oneline', '--reverse']).split('n')
                                      if first_index >= 0:
                                      commit1 = logs[first_index].split(' ')[0]
                                      if second_index >= 0:
                                      commit2 = logs[second_index].split(' ')[0]
                                      except ValueError:
                                      if first != '0':
                                      commit1 = first
                                      if second != '0':
                                      commit2 = second
                                      return commit1, commit2

                                      def validateCommitIds(name, commit1, commit2):
                                      if commit1 == None and commit2 == None:
                                      print "Nothing to do, exit!"
                                      return False
                                      try:
                                      if commit1 != None:
                                      subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit1]).strip()
                                      if commit2 != None:
                                      subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit2]).strip()
                                      except subprocess.CalledProcessError:
                                      return False
                                      return True

                                      def cleanup(commit1, commit2):
                                      subprocess.check_output(['rm', '-rf', '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                      def checkoutCommit(name, commit):
                                      if commit != None:
                                      subprocess.check_output(['git', 'clone', name, '/tmp/'+commit])
                                      subprocess.check_output(['git', '-C', '/tmp/'+commit, 'checkout', commit])
                                      else:
                                      subprocess.check_output(['mkdir', '/tmp/0'])

                                      def compare(tool, commit1, commit2):
                                      subprocess.check_output([tool, '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                      if __name__=='__main__':
                                      tool = getTool()
                                      if tool == None:
                                      print "No GUI diff tools"
                                      sys.exit(0)
                                      if len(sys.argv) != 4:
                                      printUsageAndExit()

                                      name, first, second = None, 0, 0
                                      try:
                                      name, first, second = sys.argv[1], sys.argv[2], sys.argv[3]
                                      except IndexError:
                                      printUsageAndExit()

                                      commit1, commit2 = getCommitIds(name, first, second)

                                      if not validateCommitIds(name, commit1, commit2):
                                      sys.exit(0)

                                      cleanup(commit1, commit2)
                                      checkoutCommit(name, commit1)
                                      checkoutCommit(name, commit2)

                                      try:
                                      compare(tool, commit1, commit2)
                                      except KeyboardInterrupt:
                                      pass
                                      finally:
                                      cleanup(commit1, commit2)
                                      sys.exit(0)





                                      share|improve this answer


























                                        0












                                        0








                                        0






                                        I wrote a script which displays diff between two commits, works well on Ubuntu.



                                        https://gist.github.com/jacobabrahamb4/a60624d6274ece7a0bd2d141b53407bc



                                        #!/usr/bin/env python
                                        import sys, subprocess, os

                                        TOOLS = ['bcompare', 'meld']

                                        def getTool():
                                        for tool in TOOLS:
                                        try:
                                        out = subprocess.check_output(['which', tool]).strip()
                                        if tool in out:
                                        return tool
                                        except subprocess.CalledProcessError:
                                        pass
                                        return None

                                        def printUsageAndExit():
                                        print 'Usage: python bdiff.py <project> <commit_one> <commit_two>'
                                        print 'Example: python bdiff.py <project> 0 1'
                                        print 'Example: python bdiff.py <project> fhejk7fe d78ewg9we'
                                        print 'Example: python bdiff.py <project> 0 d78ewg9we'
                                        sys.exit(0)

                                        def getCommitIds(name, first, second):
                                        commit1 = None
                                        commit2 = None
                                        try:
                                        first_index = int(first) - 1
                                        second_index = int(second) - 1
                                        if int(first) < 0 or int(second) < 0:
                                        print "Cannot handle negative values: "
                                        sys.exit(0)
                                        logs = subprocess.check_output(['git', '-C', name, 'log', '--oneline', '--reverse']).split('n')
                                        if first_index >= 0:
                                        commit1 = logs[first_index].split(' ')[0]
                                        if second_index >= 0:
                                        commit2 = logs[second_index].split(' ')[0]
                                        except ValueError:
                                        if first != '0':
                                        commit1 = first
                                        if second != '0':
                                        commit2 = second
                                        return commit1, commit2

                                        def validateCommitIds(name, commit1, commit2):
                                        if commit1 == None and commit2 == None:
                                        print "Nothing to do, exit!"
                                        return False
                                        try:
                                        if commit1 != None:
                                        subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit1]).strip()
                                        if commit2 != None:
                                        subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit2]).strip()
                                        except subprocess.CalledProcessError:
                                        return False
                                        return True

                                        def cleanup(commit1, commit2):
                                        subprocess.check_output(['rm', '-rf', '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                        def checkoutCommit(name, commit):
                                        if commit != None:
                                        subprocess.check_output(['git', 'clone', name, '/tmp/'+commit])
                                        subprocess.check_output(['git', '-C', '/tmp/'+commit, 'checkout', commit])
                                        else:
                                        subprocess.check_output(['mkdir', '/tmp/0'])

                                        def compare(tool, commit1, commit2):
                                        subprocess.check_output([tool, '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                        if __name__=='__main__':
                                        tool = getTool()
                                        if tool == None:
                                        print "No GUI diff tools"
                                        sys.exit(0)
                                        if len(sys.argv) != 4:
                                        printUsageAndExit()

                                        name, first, second = None, 0, 0
                                        try:
                                        name, first, second = sys.argv[1], sys.argv[2], sys.argv[3]
                                        except IndexError:
                                        printUsageAndExit()

                                        commit1, commit2 = getCommitIds(name, first, second)

                                        if not validateCommitIds(name, commit1, commit2):
                                        sys.exit(0)

                                        cleanup(commit1, commit2)
                                        checkoutCommit(name, commit1)
                                        checkoutCommit(name, commit2)

                                        try:
                                        compare(tool, commit1, commit2)
                                        except KeyboardInterrupt:
                                        pass
                                        finally:
                                        cleanup(commit1, commit2)
                                        sys.exit(0)





                                        share|improve this answer














                                        I wrote a script which displays diff between two commits, works well on Ubuntu.



                                        https://gist.github.com/jacobabrahamb4/a60624d6274ece7a0bd2d141b53407bc



                                        #!/usr/bin/env python
                                        import sys, subprocess, os

                                        TOOLS = ['bcompare', 'meld']

                                        def getTool():
                                        for tool in TOOLS:
                                        try:
                                        out = subprocess.check_output(['which', tool]).strip()
                                        if tool in out:
                                        return tool
                                        except subprocess.CalledProcessError:
                                        pass
                                        return None

                                        def printUsageAndExit():
                                        print 'Usage: python bdiff.py <project> <commit_one> <commit_two>'
                                        print 'Example: python bdiff.py <project> 0 1'
                                        print 'Example: python bdiff.py <project> fhejk7fe d78ewg9we'
                                        print 'Example: python bdiff.py <project> 0 d78ewg9we'
                                        sys.exit(0)

                                        def getCommitIds(name, first, second):
                                        commit1 = None
                                        commit2 = None
                                        try:
                                        first_index = int(first) - 1
                                        second_index = int(second) - 1
                                        if int(first) < 0 or int(second) < 0:
                                        print "Cannot handle negative values: "
                                        sys.exit(0)
                                        logs = subprocess.check_output(['git', '-C', name, 'log', '--oneline', '--reverse']).split('n')
                                        if first_index >= 0:
                                        commit1 = logs[first_index].split(' ')[0]
                                        if second_index >= 0:
                                        commit2 = logs[second_index].split(' ')[0]
                                        except ValueError:
                                        if first != '0':
                                        commit1 = first
                                        if second != '0':
                                        commit2 = second
                                        return commit1, commit2

                                        def validateCommitIds(name, commit1, commit2):
                                        if commit1 == None and commit2 == None:
                                        print "Nothing to do, exit!"
                                        return False
                                        try:
                                        if commit1 != None:
                                        subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit1]).strip()
                                        if commit2 != None:
                                        subprocess.check_output(['git', '-C', name, 'cat-file', '-t', commit2]).strip()
                                        except subprocess.CalledProcessError:
                                        return False
                                        return True

                                        def cleanup(commit1, commit2):
                                        subprocess.check_output(['rm', '-rf', '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                        def checkoutCommit(name, commit):
                                        if commit != None:
                                        subprocess.check_output(['git', 'clone', name, '/tmp/'+commit])
                                        subprocess.check_output(['git', '-C', '/tmp/'+commit, 'checkout', commit])
                                        else:
                                        subprocess.check_output(['mkdir', '/tmp/0'])

                                        def compare(tool, commit1, commit2):
                                        subprocess.check_output([tool, '/tmp/'+(commit1 if commit1 != None else '0'), '/tmp/'+(commit2 if commit2 != None else '0')])

                                        if __name__=='__main__':
                                        tool = getTool()
                                        if tool == None:
                                        print "No GUI diff tools"
                                        sys.exit(0)
                                        if len(sys.argv) != 4:
                                        printUsageAndExit()

                                        name, first, second = None, 0, 0
                                        try:
                                        name, first, second = sys.argv[1], sys.argv[2], sys.argv[3]
                                        except IndexError:
                                        printUsageAndExit()

                                        commit1, commit2 = getCommitIds(name, first, second)

                                        if not validateCommitIds(name, commit1, commit2):
                                        sys.exit(0)

                                        cleanup(commit1, commit2)
                                        checkoutCommit(name, commit1)
                                        checkoutCommit(name, commit2)

                                        try:
                                        compare(tool, commit1, commit2)
                                        except KeyboardInterrupt:
                                        pass
                                        finally:
                                        cleanup(commit1, commit2)
                                        sys.exit(0)






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jul 2 at 15:22

























                                        answered Jul 2 at 10:27









                                        Jacob Abraham

                                        69788




                                        69788























                                            0














                                            Since Git 2.19, you can simply use:



                                            git range-diff <rev1>...<rev2>






                                            share|improve this answer


























                                              0














                                              Since Git 2.19, you can simply use:



                                              git range-diff <rev1>...<rev2>






                                              share|improve this answer
























                                                0












                                                0








                                                0






                                                Since Git 2.19, you can simply use:



                                                git range-diff <rev1>...<rev2>






                                                share|improve this answer












                                                Since Git 2.19, you can simply use:



                                                git range-diff <rev1>...<rev2>







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Oct 15 at 15:53









                                                Tomáš Diviš

                                                57735




                                                57735






























                                                    draft saved

                                                    draft discarded




















































                                                    Thanks for contributing an answer to Stack Overflow!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.





                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                    Please pay close attention to the following guidance:


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1191282%2fhow-to-see-the-changes-between-two-commits-without-commits-in-between%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                                    ComboBox Display Member on multiple fields

                                                    Is it possible to collect Nectar points via Trainline?