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

前端 未结 13 2055
青春惊慌失措
青春惊慌失措 2020-12-07 07:12

How can I diff a file, say pom.xml, from the master branch to an arbitrary older version in Git?

13条回答
  •  鱼传尺愫
    2020-12-07 07:27

    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
    

提交回复
热议问题