How to diff one file to an arbitrary version in Git ?

How to diff one file to an arbitrary version in Git ?

Asked on January 10, 2019 in Git.
Add Comment


  • 4 Answer(s)

    Try this;

    git diff master~20:pom.xml pom.xml
    
    

    Analyze your current pom.xml to the  one from master to  replace master~20, of course, with the object name that may commit many other ways of specifying a revision.

    Not the version dedicated in master to analyze the old pom.xml to the version in your working tree .

    git diff master~20:pom.xml master:pom.xml
    
    
    Answered on January 10, 2019.
    Add Comment

    Arbitrary version in Git:

    git diff <revision> <path>
    
    

    For instance:

    git diff b0d14a4 foobar.txt
    
    
    Answered on January 10, 2019.
    Add Comment

    The final commit of a single file:

    git log -p -1 filename
    
    

    The diff of the file in git, is not analyze your local file.

    Answered on January 10, 2019.
    Add Comment

    You can do:

    git diff master~20:pom.xml pom.xml
    

    … to compare your current pom.xml to the one from master 20 revisions ago through the first parent. You can replace master~20, of course, with the object name (SHA1sum) of a commit or any of the many other ways of specifying a revision.

    Note that this is actually comparing the old pom.xml to the version in your working tree, not the version committed in master. If you want that, then you can do the following instead:

    git diff master~20:pom.xml master:pom.xml
    
    Answered on February 20, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.