如何处理/修复git添加/添加冲突? [英] How to handle/fix git add/add conflicts?

查看:330
本文介绍了如何处理/修复git添加/添加冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定何时发生此错误,我在Google中没有找到任何描述。

所以我的同事提交了一些新文件并更改了branch1上的文件。然后我得到了这些变化,并将它们合并到我的分支(分支2),但不使用Git合并,但手动使用超越比较(我知道这是一个不好的做法手动合并)。但是,手动合并它们并将我的分支中的新文件复制粘贴后,我在branch2中提交了该工作。但是,现在,当他们试图从我使用git merge origin / branch2获得一些更改时,他们在最初添加的新文件中收到了很多git添加/添加冲突。



有人可以告诉我为什么git将这些文件视为冲突,尽管它们是相同的?并且应该如何处理这些冲突?

解决方案

您收到 CONFLICT(添加/添加):Merge conflict in .. 。冲突是因为文件实际上不完全相同。他们可能从远处看起来几乎相同,但它们是完全不同的。



如果甚至有一点差异,Git不能知道哪个文件是正确的。一个分支表示添加此文件,另一个分支表示添加此文件,具有相同名称但内容不同,只有您可以确定哪一个是正确的。



您可以通过以下方式确认区别:

  git diff other_branch路径/ to / file 

或者在合并之后,在冲突状态下,您可以简单地看到 git diff

要解决这种冲突,您必须决定哪个分支具有正确的内容,并检出该分支中的文件。要选择当前分支中的版本:

  git checkout路径/ to / file 

选择另一个分支中的版本:

  git checkout other_branch path / to / file 

长期解决方案是避免您已经知道自己不好。

I'm not sure when this error occurs, I haven't found any descriptions in google.

So my colleagues commited some new files and changed files on branch1. I then got these changes and merged them into my branch(branch2) but NOT using git merge but manually using beyond compare (I know it's a bad practice merging manually). However, after merging them manually and copy-pasting the new files in my branch as well, I commited the work in branch2. However, now, when they tried to get some changes from me using git merge origin/branch2 they receive a lot of git "add/add" conflicts on the new files they initially added.

Can anybody tell me why git sees these files as conflicts although they are the same? And how should these conflicts be handled?

解决方案

You get CONFLICT (add/add): Merge conflict in ... conflicts because the files are in fact NOT exactly the same. They may look pretty much the same from a distance, but they are definitely different.

If there is even one bit of difference, Git cannot know which file is the right one. One branch says "add this file", another branch says "add this file", with same name but different content, only you can tell which one is the right one.

You can confirm the difference with:

git diff other_branch path/to/file

Or after the merge, in the conflicted state, you can see the problem with simply git diff.

To resolve such conflict, you have to decide which branch has the right content, and checkout the file from that branch. To choose the version in the current branch:

git checkout path/to/file

To choose the version in the other branch:

git checkout other_branch path/to/file

The long-term solution is to avoid practices that you already know yourself to be bad.

这篇关于如何处理/修复git添加/添加冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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