Search code examples
gitversion-control

Git producing .bak and .orig files when merging


I am trying to merge my UAT1 branch into MASTER branch and when I resolved all the conflicts, the files that were generated had .bak and .orig extensions. I looked at questions on here that refer to .orig file and learned that it's okay to remove them, however, what files do I commit? If I remove all the .bak and .orig files then there will be no files to commit hence all the files I merged will be gone.

I use winmerge as my mergetool.

My git status image


Solution

  • Files with .bak or .orig extensions shouldn’t be committed in version control.

    To ignore the .bak and .orig files during merge, you can use below steps:

    1. Add *.bak and *.orig in .gitignore.
    2. Change mergetool.keepBackup option for git config as false

      git config --global mergetool.keepBackup false
      

    Now if you execute git status during merging, there will only show the changes for the files which states are changes to be committed and changes not staged for commit.

    • If you only want to merge the .java file (changes to be committed state) into master branch, you can execute git commit to finish the merge.
    • If you want to merge all the files as .java (changes to be committed state), .gitignore and xx.xx.xx.xx.component (changes not staged for commit state) into master branch, you can execute git commit -a to finish the merge.