GIT 损坏的文件 (<<<<<<<<HEAD)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15291056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:17:29  来源:igfitidea点击:

GIT corrupt files (<<<<<<<<HEAD)

gitgit-mergemerge-conflict-resolution

提问by ErikTJ

I have this in my files after some trouble with VS2012 git-plugin:

在 VS2012 git-plugin 出现问题后,我的文件中有这个:

using Microsoft.VisualStudio.TestTools.UnitTesting;
<<<<<<< HEAD
using NHibernate;
=======
>>>>>>> dd2c3d7dfe81074e7c5a73f8e4ca2584481a74f1

namespace Controll.Hosting.Tests
{
[TestClass]
public class TestBase
{
<<<<<<< HEAD
    protected ISessionFactory SessionFactory;

    [TestInitialize]
    public void InitializeTestBase()
    {
            SessionFactory = NHibernateHelper.GetSessionFactoryForMockedData();
=======
    [ClassInitialize]
    public void InitializeTest()
    {
        Console.WriteLine("Settings NHibernateHelper.IsInTesting -> True");
        NHibernateHelper.IsInTesting = true;
>>>>>>> dd2c3d7dfe81074e7c5a73f8e4ca2584481a74f1
        }
    }
}

How can i reset my files?

如何重置我的文件?

回答by alestanis

What you had wasn't troublebut conflicts. This happens when the files are modified by two different persons at the same place (you both add/remove/modify things inside the same lines).

你所拥有的不是麻烦,而是冲突。当文件被两个不同的人在同一个地方修改时会发生这种情况(你在同一行内添加/删除/修改内容)。

You can simply update your files manually, by deciding to keep everything between <<<<<<< HEADand =======, or between =======and >>>>>>>, or some mix of the two. Once you resolveall your conflicts, you just need to commit your changes.

您可以简单地手动更新您的文件,决定将所有内容保留在<<<<<<< HEADand之间=======,或在=======and之间,或两者的>>>>>>>某种混合。一旦你解决所有的冲突,你只需要提交更改。

To discard local changes on a file, you can do

要放弃对文件的本地更改,您可以执行

git checkout yourfile

or, for all files using

或者,对于所有使用的文件

git checkout -- .

You can also decide, for each file, if you want to keep your version or the repository version with

您还可以决定,对于每个文件,是否要保留您的版本或存储库版本

git checkout --ours yourfile # Your version
git checkout --theirs yourfile # Repository version

回答by cfi

Your Q is answered best by alestanis, already. Still for easy lookup:

alestanis 已经回答了您的问题。还是为了方便查找:

An explanation of those conflict markers >>>>>... <<<<<can be found at this question.

这些冲突标记的解释>>>>>......<<<<<可以在这个问题中找到。

There's more info about merging at this Q.

这个 Q有更多关于合并的信息。

And git help mergeis quite explicitly helpful as well:

并且git help merge也非常有帮助:

HOW TO RESOLVE CONFLICTS

After seeing a conflict, you can do two things:

· Decide not to merge. The only clean-ups you need are to reset the index file to the HEAD commit to reverse 2. and to clean up working tree changes made by 2. and 3.; git merge --abortcan be used for this.

· Resolve the conflicts. Git will mark the conflicts in the working tree. Edit the files into shape and git addthem to the index. Use git committo seal the deal.

You can work through the conflict with a number of tools:

· Use a mergetool. git mergetoolto launch a graphical mergetool which will work you through the merge.

· Look at the diffs. git diffwill show a three-way diff, highlighting changes from both the HEAD and MERGE_HEAD versions.

· Look at the diffs from each branch. git log --merge -p <path>will show diffs first for the HEAD version and then the MERGE_HEAD version.

· Look at the originals. git show :1:filenameshows the common ancestor, git show :2:filenameshows the HEAD version, and git show :3:filenameshows the MERGE_HEAD version.

如何解决冲突

看到冲突后,你可以做两件事:

· 决定不合并。您需要做的唯一清理工作是将索引文件重置为 HEAD 提交以反转 2. 并清理由 2. 和 3. 所做的工作树更改;git merge --abort可以用于此。

· 解决冲突。Git 会在工作树中标记冲突。将文件编辑成形状并将git add它们添加到索引中。用于 git commit达成交易。

您可以使用多种工具解决冲突:

· 使用合并工具。 git mergetool启动一个图形合并工具,它将帮助您完成合并。

·看看差异。 git diff将显示三向差异,突出显示 HEAD 和 MERGE_HEAD 版本的更改。

· 查看每个分支的差异。 git log --merge -p <path>将首先显示 HEAD 版本的差异,然后是 MERGE_HEAD 版本。

· 看看原件。 git show :1:filename显示共同祖先,git show :2:filename显示 HEAD 版本,并git show :3:filename显示 MERGE_HEAD 版本。

回答by Dan

Using SourceTree for git to manage my builds with Kdiff installed has helped me resolve 99% of these issues really efficiently.

在安装了 Kdiff 的情况下,使用 SourceTree for git 管理我的构建帮助我真正有效地解决了 99% 的这些问题。

I'm just left with trying to remove these from my SOU file in .Net, usually replacing the SOU file with an older version resolves this.

我只剩下尝试从 .Net 中的 SOU 文件中删除这些,通常用旧版本替换 SOU 文件可以解决这个问题。