Git可以合并“使用” git blame -C找到的信息吗?

Ghi*_*que 5 git git-merge branching-and-merging

读完这个问题后,我想到了这个问题:Git真的可以跟踪单个功能从一个文件到另一个文件的移动吗?如果是这样,怎么办?

这是worfklow:

“很久以前”,我们将一个大文件拆分为folder/file.py许多文件:folder1/file.pyfolder2/file.py依此类推。

git blame -C当我们查看时folder2/file.py,正确显示了该代码的历史记录,我们看到一些提交是在拆分之前进行的。

问题是我们继续维护仍然具有的旧版本代码,folder/file.py当我们将修补程序合并回“当前”版本时,git继续重新创建该文件夹folder,并且看不到folder/file.py应将所做的修补程序合并到其中folder1/file.pyfolder2/file.py取决于此代码块现在位于何处。

我快速看了一下,git help merge但没有发现任何东西。

Chr*_*her 0

合并不能利用git blame -C,但git merge具有重命名检测。从手册页:

   rename-threshold=<n>
   Controls the similarity threshold used for rename detection. See also git-diff(1) -M.
Run Code Online (Sandbox Code Playgroud)

Git 的重命名阈值可能太高,无法在合并期间检测到您的重命名。检测的计算量也可能过于密集。尝试使用较低的重命名阈值(例如 75)进行测试合并:

git merge -X rename-threshold=75 <branch>
Run Code Online (Sandbox Code Playgroud)

您可能需要花一些时间才能找到正确的数字,如果 git 由于计算难度太大而退出,请尝试设置git config merge.renamelimit 0上面链接的线程中讨论的值。

如果上述方法失败,这个答案也可能有帮助。我还没有尝试-X ignore-space-change过链接脚本,但可能值得研究。