为什么git显示两个显然相同的添加文件之间的冲突? [英] Why does git show a conflict between two apparently identical added files?

查看:947
本文介绍了为什么git显示两个显然相同的添加文件之间的冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在TFS中启动的项目,然后转移到Git。不幸的是,把它移动到Git的人只是检查了当前文件而不是使用git-tfs。我尝试在Git中使用git-tfs从TFS提交的提交之前重新提交他在Git中的新提交。

为了做到这一点,我只是将他的投标在git-tfs提交之上提交。 (我意识到这会搞乱远程Git分支,但是我们是一个小团队,它会好的,我也尝试了樱桃采摘,但我碰到了同样的问题。)



我碰到的问题是一组看起来像这样的冲突:

 < <<<<<< HEAD 
namespace OurNiftyProject
{
public enum CardType
{
Visa = 0,
MasterCard = 1
}
}
|||||||合并共同祖先
=======
名称空间OurNiftyProject
{
public enum CardType
{
Visa = 0,
MasterCard = 1
}
}
>>>>>>>>添加一堆东西。

看来这是添加这些文件的TFS端提交和在Git一边添加它们(因为Git repo开始是空的)。

逻辑上可能是跳过这个提交,也许有一些其中的文件(比如几百个中的十个)是新的。当然,这些不会引起冲突。



为什么Git不能自行判断这两个文件是相同的?即使我使用 - ignore-whitespace 当我重新绑定时,Git仍然会显示几十个像这样的文件,看起来是完全相同的。我不知道如何解决这个问题。 解决方案

它应该是关于行尾差异的,如 ebneter 评论。

我已经详细描述了很久以前git merge如何不善于忽略这些差异(而不是空白区别):

git-merge可能会忽略行结束差异吗?



这就是为什么一致的 em> eol转换策略对于异构环境中的这些存储库是必需的。

请参阅使用代码

I have a project that was started in TFS, then moved to Git. Unfortunately, the guy who moved it to Git just checked in the current files instead of using git-tfs. I'm trying to rebase his new commits in Git on top of the commits I pulled from TFS using git-tfs.

To do this, I'm simply rebasing his commits on top of the git-tfs commits. (I realize this will mess up remote Git branches, but we're a small team and it'll be OK. I've also tried cherry-picking instead but I hit the same problem.)

The problem I'm running into is a set of conflicts that look like this:

<<<<<<< HEAD
namespace OurNiftyProject
{
    public enum CardType
    { 
        Visa = 0,
        MasterCard = 1
    }
}
||||||| merged common ancestors
=======
namespace OurNiftyProject
{
    public enum CardType
    { 
        Visa = 0,
        MasterCard = 1
    }
}
>>>>>>> Add a bunch of stuff.

It appears that this is a conflict between a commit from the TFS side that added these files, and a commit on the Git side that added them (as the Git repo started out empty).

The logical thing would be to skip this commit, perhaps, but there are a few files in it (say ten out of a couple hundred) that are new. Those don't cause conflicts, of course.

Why can't Git figure out on its own that the two files are identical? Even if I use --ignore-whitespace when I rebase, Git still shows dozens of files like this that appear to be identical. I'm at a loss for how to resolve this.

解决方案

It should be about line-ending differences, as ebneter comments.
I have already detailed a long time ago how git merge wasn't good at ignoring those differences (as opposed to whitespaces differences):
"Is it possible for git-merge to ignore line-ending differences?"

That is why a consistent eol conversion policy is necessary for those repository on heterogeneous environment.
See "Distributing git configuration with the code".

这篇关于为什么git显示两个显然相同的添加文件之间的冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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