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

前端 未结 13 2071
青春惊慌失措
青春惊慌失措 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:28

    Generic Syntax :

    $git diff oldCommit..newCommit -- **FileName.xml > ~/diff.txt
    

    for all files named "FileName.xml" anywhere in your repo.

    Notice the space between "--" and "**"

    Answer for your question:

    $git checkout master
    $git diff oldCommit..HEAD -- **pom.xml 
    or
    $git diff oldCommit..HEAD -- relative/path/to/pom.xml 
    

    as always with git, you can use a tag/sha1/"HEAD^" to id a commit.

    Tested with git 1.9.1 on Ubuntu.

提交回复
热议问题