解决 git 中“两者都添加"的合并冲突? [英] Resolving a 'both added' merge conflict in git?

查看:60
本文介绍了解决 git 中“两者都添加"的合并冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 git 中变基,我得到的一个冲突是两者都添加"——也就是说,在我的分支中独立添加了完全相同的文件名,而在我正在变基的分支中.git status 告诉我:

I'm rebasing in git, and one conflict I get is 'both added' - that is, exactly the same filename has been added independently in my branch, and in the branch I'm rebasing on. git status tells me:

# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both added:         src/MyFile.cs

我的问题是,我该如何解决这个问题?我必须使用合并工具还是有一种方法可以仅从命令行执行此操作?如果我 git rm src/MyFile.cs,git 怎么知道我想删除哪个文件版本以及我想保留哪个版本?

My question is, how do I resolve this? Must I use a merge tool or is there a way I can do it just from the commandline? If I git rm src/MyFile.cs, how does git know which file version I want to remove and which I want to keep?

推荐答案

如果您使用 git rm git 将从索引中删除该路径的所有版本,因此您的解析操作将使您没有任何版本.

If you use git rm git will remove all versions of that path from the index so your resolve action will leave you without either version.

您可以使用 git checkout --ours src/MyFile.cs 从要重新定位的分支中选择版本或 git checkout --theirs src/MyFile.cs 从你正在变基的分支中选择版本.

You can use git checkout --ours src/MyFile.cs to choose the version from the branch onto which you are rebasing or git checkout --theirs src/MyFile.cs to choose the version from the branch which you are rebasing.

如果您想要混合,则需要使用合并工具或手动编辑.

If you want a blend you need to use a merge tool or edit it manually.

这篇关于解决 git 中“两者都添加"的合并冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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