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

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

    git doesn't actually track renames at all. A rename is just a delete and add, that's all. Any tools who show renames reconstruct them from this history information.

    As such, tracking function renames is a simple matter of analyzing the diffs of all files in each commit after the fact. There's nothing particularly impossible about it; the existing rename tracking already handles 'fuzzy' renames, in which some changes are done to the file as well as renaming it; this requires looking at the contents to the files. It would be a simple extension to look for function renames as well.

    I don't know if the base git tools actually do this however - they try to be language neutral, and function identification is very much not language neutral.

提交回复
热议问题