git因两个分支重命名而导致合并冲突 - 如何修复&将来避免? [英] git merge conflict due to renaming in two branches - how to fix & avoid in future?

查看:729
本文介绍了git因两个分支重命名而导致合并冲突 - 如何修复&将来避免?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个本地分行 master dev 。这两个分支都包含三个文件夹:

  projectBeta 
项目
project_v1

我想保留 projectBeta 并删除项目 code>和 project_v1 ,然后将 projectBeta 重命名为项目。所以这就是我在两个分支上分别做的事情,我一直在做。直到我试图将 dev 分支合并到master时,所有的东西都看起来很好,我得到了一堆这样的错误:

  CONFLICT(重命名/删除):在dev中重命名projectBeta / test.c-> project / test.c并在HEAD 
CONFLICT(重命名/删除) :在HEAD中重命名project_v1 / test.c-> project / test.c并在dev
中删除

所以它看起来像Git在不同的分支以不同的方式跟踪重命名。



如果我做一个 git status ,我得到

 #分支大师
#未合并路径:
#(使用git add / rm< file> ...适当标记分辨率)

#由我们添加:project / test.c

没有更改添加到提交(使用git add和/或git commit -a)

首先我不明白这就是为什么当合并报告称其被我们和第二方更名和删除时,地位只是说它是由我们添加的em?



其次,我想使用test.c的开发分支版本(他们),但是现在当我尝试时

  git co  - 他们的项目/ test.c 

我得到

 错误:path'project / test.c'没有他们的版本

code>

...所以我不知道如何确保合并将使用来自dev分支的内容?



最后,有没有一种最佳实践方法可以避免将来出现这样的混乱?基本上,在内容尚未准备好合并的分支中独立地更改文件夹结构...

解决方案

试试这个

  git pull 



<

  git add --all 
git转到文件夹以删除项目和project_v1,将projectBeta重命名为项目。提交
git push

并且您对其他分支做同样的事情

I have two local branches master and dev. Both branches contained three folders:

projectBeta
project
project_v1

I wanted to just keep projectBeta and remove project and project_v1 and then rename projectBeta as project. So that's what I did separately on both branches, committing as I went along. All looked good until I tried to then merge the dev branch to master, and I got a pile of these kinds of errors:

CONFLICT (rename/delete): Rename projectBeta/test.c->project/test.c in dev and deleted in HEAD
CONFLICT (rename/delete): Rename project_v1/test.c->project/test.c in HEAD and deleted in dev

So it looks like Git tracked the renames in different ways in the different branches.

If I do a git status, I get

# On branch master
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   added by us:        project/test.c
#
no changes added to commit (use "git add" and/or "git commit -a")

First thing I don't understand is why the status just says that it's "added by us" when the merge report says it's renamed and deleted by both us and them?

Secondly, I want to use the dev branch version (them) of test.c, but now when I try

git co --theirs project/test.c

I get

error: path 'project/test.c' does not have their version

...so I don't know how to ensure the merge will use the content from the dev branch?

Finally, is there a best-practice way to avoid such a mess like this in the future? Basically, changing folder structures independently in branches where the content is not ready to merge first...

解决方案

try this

git pull

go to folder to delete project and project_v1, rename projectBeta to project.

git add --all
git commit 
git push

and you do the same for other branch

这篇关于git因两个分支重命名而导致合并冲突 - 如何修复&amp;将来避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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