Git mergetool generates unwanted .orig files

前端 未结 10 1954
予麋鹿
予麋鹿 2020-11-30 16:16

When I do a merge conflict resolution with Kdiff3 (and other merge tool I tried) I noticed that on resolution a *.orig file is created. Is there a way for it to

相关标签:
10条回答
  • 2020-11-30 16:44

    You have to be a little careful with using kdiff3 as while git mergetool can be configured to save a .orig file during merging, the default behaviour for kdiff3 is to also save a .orig backup file independently of git mergetool.

    You have to make sure that mergetool backup is off:

    git config --global mergetool.keepBackup false
    

    and also that kdiff3's settings are set to not create a backup:

    Configure/Options => Directory Merge => Backup Files (*.orig)
    
    0 讨论(0)
  • 2020-11-30 16:47

    To be clear, the correct git command is:

    git config --global mergetool.keepBackup false
    

    Both of the other answers have typos in the command line that will cause it to fail or not work correctly.

    0 讨论(0)
  • 2020-11-30 16:48

    I simply use the command

    git clean -n *.orig
    

    check to make sure only file I want remove are listed then

    git clean -f *.orig
    
    0 讨论(0)
  • 2020-11-30 16:50

    A possible solution from git config:

    git config --global mergetool.keepBackup false
    

    After performing a merge, the original file with conflict markers can be saved as a file with a .orig extension.
    If this variable is set to false then this file is not preserved.
    Defaults to true (i.e. keep the backup files).

    The alternative being not adding or ignoring those files, as suggested in this gitguru article,

    git mergetool saves the merge-conflict version of the file with a “.orig” suffix.
    Make sure to delete it before adding and committing the merge or add *.orig to your .gitignore.

    Berik suggests in the comments to use:

    find . -name \*.orig 
    find . -name \*.orig -delete
    

    Charles Bailey advises in his answer to be aware of internal diff tool settings which could also generate those backup files, no matter what git settings are.

    • kdiff3 has its own settings (see "Directory merge" in its manual).
    • other tools like WinMerge can have their own backup file extension (WinMerge: .bak, as mentioned in its manual).

    So you need to reset those settings as well.

    0 讨论(0)
提交回复
热议问题