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

前端 未结 5 1942
予麋鹿
予麋鹿 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

    This functionality is provided through git blame -C .

    The -C option drives git into trying to find matches between addition or deletion of chunks of text in the file being reviewed and the files modified in the same changesets. Additional -C -C, or -C -C -C extend the search.

    Try for yourself in a test repo with git blame -C and you'll see that the block of code that you just moved is originated in the original file where it belonged to.

    From the git help blame manual page:

    The origin of lines is automatically followed across whole-file renames (currently there is no option to turn the rename-following off). To follow lines moved from one file to another, or to follow lines that were copied and pasted from another file, etc., see the -C and -M options.

提交回复
热议问题