Can Git really track the movement of a single function from 1 file to another? If so, how?

前端 未结 5 1961
予麋鹿
予麋鹿 2020-12-04 11:47

Several times, I have come across the statement that, if you move a single function from one file to another file, Git can track it. For example, this entry says, \"Linus sa

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 12:43

    As of Git 2.15, git diff now supports detection of moved lines with the --color-moved option. It works for moves across files.

    It works, obviously, for colorized terminal output. As far as I can tell, there is no option to indicate moves in plain text patch format, but that makes sense.

    For default behavior, try

    git diff --color-moved
    

    The command also takes options, which currently are no, default, plain, zebra and dimmed_zebra (Use git help diff to get the latest options and their descriptions). For example:

    git diff --color-moved=zebra
    

    As to how it is done, you can glean some understanding from this email exchange by the author of the functionality.

提交回复
热议问题