读完这篇文章后我想到了这个问题:Can Git really track the movement of a single function from 1 file to another? If so, how?
这是工作流程:
“很久以前”,我们将一个大文件 folder/file.py
拆分为多个文件:folder1/file.py
,folder2/file .py
等等。
folder2/file.py
时,git blame -C
正确显示了该代码的历史记录,我们看到一些提交是在拆分之前进行的.
问题是我们继续维护仍然有 folder/file.py
的旧版本代码,当我们将修复 merge 回“当前”版本时,git 不断重新创建文件夹 folder
并且没有看到对 folder/file.py
所做的修复应该 merge 到 folder1/file.py
或 folder2/file.py
取决于这段代码现在所在的位置。
我快速查看了 git help merge
但没有找到任何相关信息。
最佳答案
merge 不能利用 git blame -C
,但是 git merge
确实有重命名检测。从手册页:
rename-threshold=<n>
Controls the similarity threshold used for rename detection. See also git-diff(1) -M.
Git 的重命名阈值可能太高而无法在 merge 期间检测到您的重命名。也可能是 detection is too computationally intense.尝试使用较低的重命名阈值(例如 75)进行测试 merge :
git merge -X rename-threshold=75 <branch>
您可能需要花一些时间才能找到正确的数字,如果 git 退出是因为它在计算上太困难,请尝试设置上面链接的线程中讨论的 git config merge.renamelimit 0
.
This answer might also help if the above fails.我没有尝试过 -X ignore-space-change
或链接脚本,但它可能值得研究。
关于git - Git能否 merge "use"git blame -C查到的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11047605/