How to do a git diff on moved/renamed file?

后端 未结 6 1477
温柔的废话
温柔的废话 2020-12-07 15:57

I moved a file using git mv. Now I would like to do a diff on the new file to compare it with the old file (with the old, now non-existent name).

How d

6条回答
  •  抹茶落季
    2020-12-07 17:02

    With git 2.9 (June 2016), you won't have to add -M anymore. git diff uses -M by default.

    See commit 5404c11, commit 9501d19, commit a9276a6, commit f07fc9e, commit 62df1e6 (25 Feb 2016) by Matthieu Moy (moy).
    (Merged by Junio C Hamano -- gitster -- in commit 5d2a30d, 03 Apr 2016)

    diff: activate diff.renames by default

    Rename detection is a very convenient feature, and new users shouldn't have to dig in the documentation to benefit from it.

    Potential objections to activating rename detection are that it sometimes fail, and it is sometimes slow. But rename detection is already activated by default in several cases like "git status" and "git merge", so activating diff.renames does not fundamentally change the situation. When the rename detection fails, it now fails consistently between "git diff" and "git status".

    This setting does not affect plumbing commands, hence well-written scripts will not be affected.

    The new tests for this feature are here.

提交回复
热议问题