Git冲突(重命名/重命名)?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (33)

合并分支之后,我收到了一个conflict (rename/rename)在一堆文件上file~HEAD,和file~my_test_branch创造出来的。如何解决这些问题?

谢谢

提问于
用户回答回答于

给定以下测试设置:

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

然后合并分支1和分支2

git merge --no-ff branch1
git merge --no-ff branch2

产量:

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")

如果你想保存一个文件,比如说new-name-2.txt:

git add new-name-2.txt
git rm new-name-1.txt will-be-renamed.txt
git commit

当然,在选择一个或另一个文件时,可能需要对引用该文件的文件进行其他更改。另外,如果在分支上对文件进行其他非重命名更改,则需要手动区分和合并这些更改,以便将它们保留在要保留的文件中。

如果想保留这两个文件:

git add new-name-1.txt new-name-2.txt
git rm will-be-renamed.txt
git commit

扫码关注云+社区