Search code examples
gitmergetool

How to change location of backup files left by failed git mergetool


When I use git merge tool and cancel it with Ctrl+C, following files are left in repository:

app/controllers/application_controller.rb.orig app/controllers/application_controller.rb.BACKUP.22361.rb app/controllers/application_controller.rb.BASE.22361.rb app/controllers/application_controller.rb.LOCAL.22361.rb app/controllers/application_controller.rb.REMOTE.22361.rb

Can I change the location of these files, so they are not written to the repository at all, even temporarily? For example to ~/.mergefiles


Solution

  • If you don't feel a strong need keep the temporary files from a broken merge at all, you may prefer to delete them entirely. To do so, set the following git config line, which will prevent them from being left behind if the mergetool exits with an error:

    git config --global mergetool.keepBackup false
    

    You may need to change some internal settings in your mergetool too, in case it's also saving backups after failed merges. If, on the other hand, you find yourself in need of the temporary files for some reason, this may not be the solution for you.