Git 冲突(重命名/重命名)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14732639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git conflict (rename/rename)
提问by spacemonkey
After merging branched I've received a conflict (rename/rename)
on bunch of files, with file~HEAD
, and file~my_test_branch
created. How to resolve these?
合并分支后,我收到了conflict (rename/rename)
一堆文件,带有file~HEAD
,并file~my_test_branch
创建。如何解决这些问题?
Thanks
谢谢
采纳答案by javabrett
Given the following test-setup:
鉴于以下测试设置:
git init resolving-rename-conflicts
cd resolving-rename-conflicts
echo "this file we will rename" > will-be-renamed.txt
git add -A
git commit -m "initial commit"
git checkout -b branch1
git rename will-be-renamed.txt new-name-1.txt
git commit -a -m "renamed a file on branch1"
git checkout -b branch2 master
git rename will-be-renamed.txt new-name-2.txt
git commit -a -m "renamed a file on branch2"
git checkout master
Then merging branch1 and branch2
然后合并 branch1 和 branch2
git merge --no-ff branch1
git merge --no-ff branch2
Yields:
产量:
CONFLICT (rename/rename): Rename "will-be-renamed.txt"->"new-name-1.txt" in branch "HEAD" rename "will-be-renamed.txt"->"new-name-2.txt" in "branch2"
Automatic merge failed; fix conflicts and then commit the result.
git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
added by us: new-name-1.txt
added by them: new-name-2.txt
both deleted: will-be-renamed.txt
no changes added to commit (use "git add" and/or "git commit -a")
If you want to keep one file, say new-name-2.txt
:
如果您想保留一个文件,请说new-name-2.txt
:
git add new-name-2.txt
git rm new-name-1.txt will-be-renamed.txt
git commit
Of course in chosing one file or the other, you may have other changes to make to files that reference this file by-name. Also, if there are other non-rename changes to the file, pre-or-post rename on the branches, you will need to manually diff and merge those to retain them in the file you are retaining.
当然,在选择一个或另一个文件时,您可能会对按名称引用此文件的文件进行其他更改。此外,如果对文件进行其他非重命名更改,在分支上重命名前或后重命名,您将需要手动比较并合并这些更改以将它们保留在您要保留的文件中。
If you instead want to keep both files:
如果您想保留这两个文件:
git add new-name-1.txt new-name-2.txt
git rm will-be-renamed.txt
git commit