21

I have this in my files after some trouble with 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?

cfi
  • 10,915
  • 8
  • 57
  • 103
ErikTJ
  • 2,001
  • 3
  • 21
  • 38
  • 8
    Those are merge conflicts. Files are not corrupted. – vedarthk Mar 08 '13 at 09:51
  • I see, can i force git overwrite everything with the new changes? – ErikTJ Mar 08 '13 at 09:52
  • You have to decide and keep data you want. GIT will only point out the conflicts. Modify that code according to answer given below and save the file. – vedarthk Mar 08 '13 at 09:54
  • 4
    possible duplicate of [Git merge left marks in my files](http://stackoverflow.com/questions/10657315/git-merge-left-marks-in-my-files) – random Jul 15 '13 at 03:27
  • 1
    @vedarthk: When this makes scripts nonfunctional, or when it happens to data files, or logs — I venture to say, for any file type — then yes, the merge conflicts have corrupted the files. Sure, the files can be recovered, but if they are made to be a non-functional state, I call them corrupted. – jvriesem Nov 14 '19 at 22:29

3 Answers3

31

What you had wasn't trouble but 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 <<<<<<< HEAD and =======, or between ======= and >>>>>>>, or some mix of the two. Once you resolve all your conflicts, you just need to commit your changes.

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
alestanis
  • 21,519
  • 4
  • 48
  • 67
  • Ok, thanks. I will accept this, but can i chose to keep all my local changes (im moving back to a really old repo and many files are affected)? – ErikTJ Mar 08 '13 at 09:55
  • 1
    @ErikTJ You shouldn't decide to do something on *all* files. The best thing, even if it's a bit annoying, is to look at each file and decide according to what git points out as conflicts. – alestanis Mar 08 '13 at 09:57
8

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

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

There's more info about merging at this Q.

And git help merge is quite explicitly helpful as well:

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 --abort can be used for this.

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

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

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

· Look at the diffs. git diff will 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:filename shows the common ancestor, git show :2:filename shows the HEAD version, and git show :3:filename shows the MERGE_HEAD version.

Community
  • 1
  • 1
cfi
  • 10,915
  • 8
  • 57
  • 103
0

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

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.

Dan
  • 11
  • 4