移动后文件被显着修改时,Git不检测重命名 [英] Git doesn't detect rename when file has been modified significantly after move

查看:130
本文介绍了移动后文件被显着修改时,Git不检测重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #!/ bin / sh -x 
rm -rf test
git init test
cd test {b $ b for I in {1..100};做
echo $ I>> x
完成
git add x
git commit -am初始提交
git checkout -b分支
git mv xy
git commit -am为{1..60}中的I重新命名为
rm y
; do
echo branch $ I>> y
为{61..100}中的I完成
;做
echo $ I>> y
完成
git commit -am更改了分支中的前60行
git checkout master
rm x
for I in {1..60}; do
echo master $ I>> x
完成
为{61..100}中的I;做
echo $ I>> x
完成
git commit -am更改了master中的前60行
git merge -s递归-X耐心分支
git状态

我想要发生的事情是让git检测到 x 被重命名为 y ,并给我机会解决合并冲突。



相反,git会忽略无法检测到)重命名,并说在分支中删除了 x ,同时创建了一个新的无关文件 y
如何说服git将其作为重命名文件处理?



谢谢!

解决方案

你是对的:git会执行重命名检测,而不是重命名跟踪,如果文件已经改变太多(对于某些太多的值),git会声明这个是一个不同的文件,而不是一个重命名的文件。



没有完美的解决方法。如果你的git足够新(1.7.4或更高版本),通常最好的选择是将 -X rename-threshold =< n> 标志传递给 git merge 。降低阈值会让git检测到更多的重命名(您可以使用 git diff -M 来测试适当的阈值)。


Consider this test script.

#!/bin/sh -x
rm -rf test
git init test
cd test
for I in {1..100}; do
    echo $I >> x
done
git add x
git commit -am "initial commit"
git checkout -b branch
git mv x y
git commit -am "renamed"
rm y
for I in {1..60}; do
    echo branch$I >> y
done
for I in {61..100}; do
    echo $I >> y
done
git commit -am "changed the first 60 lines in branch"
git checkout master
rm x
for I in {1..60}; do
    echo master$I >> x
done
for I in {61..100}; do
    echo $I >> x
done
git commit -am "changed the first 60 lines in master"
git merge -s recursive -X patience branch
git status

What I want to happen is for git to detect that x was renamed to y in the branch, and give me the opportunity to resolve the merge conflict.

Instead what happens is git ignores (fails to detect) the rename, and says that x was deleted in the branch while a new unrelated file y was created. How can I convince git to handle this as a renamed file?

Thank you!

解决方案

You are correct: git does rename-detection, rather than rename-tracking, and if the file has changed "too much" (for some value of "too much"), git declares this to be a different file, rather than a renamed file.

There is no perfect fix for this. Often the best option, if your git is new enough (1.7.4 or later), is to pass the -X rename-threshold=<n> flag to git merge. Lowering the threshold makes git detect more renames (and you can use git diff -M to test for an appropriate threshold value).

这篇关于移动后文件被显着修改时,Git不检测重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆