Git mergetool 生成不需要的 .orig 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1251681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:51:27  来源:igfitidea点击:

Git mergetool generates unwanted .orig files

gitversion-control

提问by Akeem

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

当我使用 Kdiff3(以及我尝试过的其他合并工具)进行合并冲突解决时,我注意到在解决时*.orig创建了一个文件。有没有办法让它不创建那个额外的文件?

回答by VonC

A possible solution from git config:

一个可能的解决方案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 .origextension.
If this variable is set to falsethen this file is not preserved.
Defaults to true(i.e. keep the backup files).

执行合并后,可以将带有冲突标记的原始文件另存为带有.orig扩展名的文件。
如果此变量设置false为,则不保留此文件。
默认为true(即保留备份文件)。

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

另一种方法是不添加或忽略这些文件,如这篇gitguru 文章中所建议的,

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

git mergetool使用“ .orig”后缀保存文件的合并冲突版本。
在添加和提交合并或添加*.orig到您的.gitignore.

Beriksuggests in the commentsto use:

Berik在评论中建议使用:

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

Charles Baileyadvises in his answerto be aware of internal diff tool settingswhich could also generate those backup files, no matter what git settings are.

Charles Bailey他的回答中建议注意内部差异工具设置,这些设置也可以生成这些备份文件,无论 git 设置是什么。

  • 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).
  • kdiff3 有自己的设置(请参阅其手册中的“目录合并”)。
  • WinMerge 等其他工具可以有自己的备份文件扩展名(WinMerge: .bak如其手册中所述)。

So you need to reset those settings as well.

因此,您还需要重置这些设置。

回答by CB Bailey

You have to be a little careful with using kdiff3as while git mergetoolcan be configured to save a .origfile during merging, the default behaviour for kdiff3is to also save a .origbackup file independently of git mergetool.

您必须小心使用,kdiff3因为 whilegit mergetool可以配置为.orig在合并期间保存文件,默认行为kdiff3是同时保存.orig独立于git mergetool.

You have to make sure that mergetoolbackup is off:

您必须确保mergetool备份已关闭:

git config --global mergetool.keepBackup false

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

并且 kdiff3 的设置被设置为不创建备份:

Configure/Options => Directory Merge => Backup Files (*.orig)

回答by John

To be clear, the correct git command is:

需要明确的是,正确的 git 命令是:

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.

其他两个答案在命令行中都有拼写错误,这将导致它失败或无法正常工作。

回答by xx1xx

The option to save the .orig file can be disabled by configuring KDiff3

可以通过配置 KDiff3 禁用保存 .orig 文件的选项

KDiff3 Backup file .orig option

KDiff3 备份文件 .orig 选项

回答by kghastie

I use this to clean up all files ending in ".orig":

我用它来清理所有以“.orig”结尾的文件:

function git-clean-orig {
    git status -su | grep -e"\.orig$" | cut -f2 -d" " | xargs rm -r
}

If you are a scaredy-cat :) you could leave the last part off just to list them (or leave off the -rif you want to approve each delete):

如果你是一只害怕的猫 :) 你可以把最后一部分留下来列出它们(或者-r如果你想批准每次删除,就不要留下):

function git-show-orig {
    git status -su | grep -e"\.orig$" | cut -f2 -d" "
}

回答by Rodneyk

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

回答by haleonj

Besides the correct answers offered as long term solutions, you can use git to remove all unnecessary files once for you with the git clean -fcommand but use git clean --dry-runfirst to ensure nothing unintended would happen.

除了作为长期解决方案提供的正确答案之外,您还可以使用 gitgit clean -f使用命令为您删除所有不必要的文件,但git clean --dry-run首先使用以确保不会发生任何意外。

This has the benefit of using tested built in functionality of Git over scripts specific to your OS/shell to remove the files.

这样做的好处是使用经过测试的 Git 内置功能而不是特定于您的 OS/shell 的脚本来删除文件。

回答by cd491415

Or just add

或者只是添加

*.orig

*.orig

to your global gitignore

到您的全球 gitignore

回答by Atul

git config --global mergetool.keepBackup false

This should work for Beyond Compare (as mergetool) too

这也适用于 Beyond Compare(作为合并工具)

回答by michal

Windows:

视窗:

  1. in File Win/Users/HOME/.gitconfigset mergetool.keepTemporaries=false
  2. in File git/libexec/git-core/git-mergetool, in the function cleanup_temp_files()add rm -rf -- "$MERGED.orig"within the else block.
  1. 在文件Win/Users/HOME/.gitconfig集中mergetool.keepTemporaries=false
  2. 在 File 中git/libexec/git-core/git-mergetool,在else 块中的cleanup_temp_files()add函数中rm -rf -- "$MERGED.orig"