Git冲突(重命名/重命名) [英] Git conflict (rename/rename)

查看:983
本文介绍了Git冲突(重命名/重命名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

合并分支后,我收到了冲突(重命名/重命名)一堆文件,其中 file〜HEAD ,并创建 file〜my_test_branch 。如何解决这些问题?



谢谢

解决方案



  git init解析 - 重命名 - 冲突
cd解析 - 重命名 - 冲突
echo这个文件我们将重命名> will-be-renamed.txt
git add -A
git commit -m初始提交
git checkout -b分支1
git重命名将被重命名为新的-name-1.txt
git commit -a -m在branch1上重命名一个文件
git checkout -b branch2 master
git rename will-be-renamed.txt new-name- 2.txt
git commit -a -m重命名分支2上的文件
git checkout master

然后合并分支1和分支2

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

产量:

<$在HEAD分支中重命名will-be-renamed.txt - >new-name-1.txt重命名will-be- branch2中的renamed.txt - >new-name-2.txt
自动合并失败;修复冲突,然后提交结果。

git status

分支大师
您有未合并的路径。
(修复冲突并运行git commit)

未合并路径:
(根据需要使用git add / rm< file> ...来标记分辨率)

由我们添加:new-name-1.txt
由他们添加:new-name-2.txt
同时删除:will-be-renamed.txt

没有更改添加到提交(使用git add和/或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


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?

Thanks

解决方案

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

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:

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

这篇关于Git冲突(重命名/重命名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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