Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleaning up after a conflicted git merge?

I had a small conflict in a .h header file in a project I'm working on. This project is tracked in Git.

Fortunately, the conflict was very simple to solve. I used

git mergetool

And chose the default (opendiff) which seemed to be FileMerge on my Mac. I made the appropriate changes, saved the file, and closed.

Git then asked me if the merge was successful, I said yes:

Was the merge successful? [y/n] y

But now, I have:

> git st # On branch develop # Changes to be committed: #   modified:   MyHeader.h # # Untracked files: #   (use "git add <file>..." to include in what will be committed) # #   MyHeader.h.BACKUP.52920.h #   MyHeader.h.BASE.52920.h #   MyHeader.h.LOCAL.52920.h #   MyHeader.h.REMOTE.52920.h #   MyHeader.h.orig 

Which of those extra junk conflict files were created by FileMerge, and which by Git?

And more importantly: How do I remove them?

like image 200
Craig Otis Avatar asked Mar 12 '13 23:03

Craig Otis


People also ask

How do you resolve a merge conflict on the same branch?

To fix this situation, you need to create new commits that mimic those on the branch. The easiest way to do that is with git rebase -f . Now you can merge branch in again.


2 Answers

You can simply delete them like you would any other file. For example:

rm MyHeader.h.orig 

Alternatively, if there are no other untracked files, then after you commit with

git commit -a 

you may clean your repository with

git clean -n git clean -f 

git clean -n will tell you what git clean -f will do, so you can be sure it's what you want.

like image 109
Neil Forrester Avatar answered Sep 23 '22 14:09

Neil Forrester


If they are the only untracked files, you can use git clean to delete them. Run it once with the -n flag to see what will be deleted then if you are sure, run it with -f. Don't use it if you have untracked files you want to keep!

like image 23
Ben Lings Avatar answered Sep 24 '22 14:09

Ben Lings