Rob*_*lak 6 git shell copy sh gitk
在命令行 Git 中,show,diff和log命令有一个选项--find-copies-harder.
有没有办法告诉(或修补) gitk使用它?我不时需要这个,而且我的项目足够小,所以我不关心性能下降。
(我不想再制作历史来强制复制检测。)
我注意到--find-copies-harder gitk 代码中出现了,但我不明白为什么。所以我尝试了命令行gitk --all --find-copies-harder,但它没有用:在一个从另一个版本化文件复制的新文件的提交中,gitk 仍然没有显示这个文件被复制的事实。
更新:通过进入--find-copies-harder该字段来编辑视图Additional arguments to git log:也无效:复制的(和稍微修改的)文件仍然没有显示为复制的,而在命令行git show --find-copies-harder中。
必要的改变是:
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 23d9dd1fe0..a98a115080 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7909,7 +7909,7 @@ proc diffcmd {ids flags} {
if {$log_showroot} {
lappend flags --root
}
- set cmd [concat | git diff-tree -r $flags $ids]
+ set cmd [concat | git diff-tree --find-copies-harder -r $flags $ids]
}
return $cmd
}
Run Code Online (Sandbox Code Playgroud)
这样,gitk 在以下测试存储库的第二次提交中显示副本
git init
echo "a file" > a
git add a
git commit -m "a file"
cp a b
git add b
git commit -m "a copy"
Run Code Online (Sandbox Code Playgroud)
如预期的:
-------------------------------------- b --------------------------------------
similarity index 100%
copy from a
copy to b
Run Code Online (Sandbox Code Playgroud)
但请注意,可能会出现意想不到的副作用,因为修改后的过程“diffcmd”在多个地方被调用。我没有系统地测试所有这些代码路径。
(我还将此补丁的通用版本发送到了 Git 邮件列表。)