Search code examples
gitp4merge

How did I generate all these extra files during git mergetool and how do I get rid of them?


I just setup my new git repo with p4merge setup as my external git mergetool. I'm on Mac and I just followed the git tutorial for external mergetools:

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

I worked through my merge conflicts, and I noticed it seemed to be keeping a separate instance of p4merge open for each new class conflict I opened up. In my old repo I would just hit save, close the window and git would automatically open up the next conflict (I was also on Windows at the time). Now doing so seemed to only result in the save persisting half the time, and I was having to keep entering 'git mergetool' into the terminal to get back into p4merge. After I got everything done my branch was clean but I had all these separate processes for p4merge still open. Closing them all out threw a bunch of errors in the command line and then I ended up with a TON of base/local/remote artifacts. Now the status of my branch looks something like this:

modified:   src/main/java/com/utils/ClientResponseUtils.java.orig
    deleted:    src/main/java/com/utils/ClientResponseUtils_BACKUP_70929.java
    deleted:    src/main/java/com/utils/ClientResponseUtils_BASE_70929.java
    deleted:    src/main/java/com/utils/ClientResponseUtils_LOCAL_70929.java
    deleted:    src/main/java/com/utils/ClientResponseUtils_REMOTE_70929.java
    modified:   src/main/java/com/utils/ListUtils.java.orig
    deleted:    src/main/java/com/utils/ListUtils_BACKUP_85524.java
    deleted:    src/main/java/com/utils/ListUtils_BASE_85524.java
    deleted:    src/main/java/com/utils/ListUtils_LOCAL_85524.java
    deleted:    src/main/java/com/utils/ListUtils_REMOTE_85524.java

Except MUCH, MUCH longer, it basically has a set of these for everything that I touched, and that was a lot of classes in the merge.

How do I go through this quickly without having to rm each one individually, and how do I prevent this from happening again in the future?

Looking a little further before posting, I realize this support page might help me clean up my command line usage:

http://answers.perforce.com/articles/KB/2848/

But I'm still wondering the best way to clean up such a horrible and lengthy mess, and why it happened in the first place.


Solution

  • This will help

    git config --global mergetool.keepBackup false
    

    If you are mainly concerned with not committing the files, you can add them to .gitignore:

    *_BACKUP_*
    *_BASE_*
    *_LOCAL_*
    *_REMOTE_*
    

    And you can occasionally run git clean -fx to remove them all