Getting Git to follow renamed and edited files

前端 未结 3 647
耶瑟儿~
耶瑟儿~ 2020-12-03 21:12

Questions about renaming files in Git have been asked before, but I can\'t work out a solution to my specific problem.

I have moved and edited multiple files (I didn

3条回答
  •  清歌不尽
    2020-12-03 22:11

    By default, git will check for renames whenever a file has been removed between commits -- there's no need to tell it manually. If you do actually move a file (with git mv, rather than manually removing it and adding it again) it ignores the hint. For performance reasons, the heuristics don't run all the time -- if you move a file out of the way then add an new one with the original name, the move may not be detected.

    Note that logically, git only stores the tree as it existed in each revision: it doesn't store any tracking information about changes made between revisions.

    If you want to see what's detected, you can use the -M (--find-renames) switch to git diff to show renames. This switch also turns on the heuristics, which is useful if you've got a commit that doesn't trigger them.

    This heuristic-based approach is a good reason (if you needed another one) to keep commits small and self-contained, as that makes git's job easier.

提交回复
热议问题