Cleaning up after a conflicted git merge?
Asked Answered
C

3

30

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?

Capacitance answered 12/3, 2013 at 23:1 Comment(0)
P
54

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.

Phosphoroscope answered 12/3, 2013 at 23:9 Comment(2)
Thanks - git clean -n/-f has been the go-to for a long time. You can also specify a path at the end, if you only want to perform the clean on a subfolder.Capacitance
Sometimes *.orig is in the .gitignore file. In this case the way to go is dry-run including ignored files: git clean -nx */*.orig, check and then delete git clean -fx */*.orig. Credit goes to: travisjeffery.com/b/2011/12/…Bordeaux
V
9

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!

Valdovinos answered 12/3, 2013 at 23:5 Comment(2)
Note: "if they are the only untracked files". Be very careful with git clean, as you could easily lose the very files that are not under version control! I'd recommend just removing them manually.Agnew
Or, I've gotten into the habit of using a file pattern, like: git clean -f *.origCapacitance
A
1

First commit your merge.

Once you're satisfied that all is well, simply remove these extra files manually (using rm <filename>, for example).

Agnew answered 12/3, 2013 at 23:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.