git diff file against its last change

前端 未结 3 1637
误落风尘
误落风尘 2021-01-29 17:42

Is it possible to get git to produce a diff between a specific file as it exists now, and as it existed before the last commit that changed it?

That is, if we know:

3条回答
  •  心在旅途
    2021-01-29 18:06

    One of the ways to use git diff is:

    git diff  
    

    And a common way to refer one commit of the last commit is as a relative path to the actual HEAD. You can reference previous commits as HEAD^ (in your example this will be 123abc) or HEAD^^ (456def in your example), etc ...

    So the answer to your question is:

    git diff HEAD^^ myfile
    

提交回复
热议问题