Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 763
ErikTJ Avatar asked Mar 08 '13 09:03

ErikTJ


People also ask

How do I know if my git repo is corrupted?

Git has a command to manually check integrity of the repository: git fsck . Running it lists all the errors. Luckily in my case the list was quite short so I went ahead and deleted all the objects that were listed as corrupted.

What is the effect if a file in the main repository becomes corrupted?

If Repository becomes corrupted, then the WMI service will not be able to function correctly.

How to recreate git index?

To rebuild the index, you can simply do git reset --mixed . This makes the index look like the last commit while leaving the worktree alone. If you had any local changes you git add ed but did not commit yet, you will need to re-add those.


2 Answers

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
like image 155
alestanis Avatar answered Oct 17 '22 17:10

alestanis


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.

like image 40
cfi Avatar answered Oct 17 '22 17:10

cfi