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
Git mergetool generates unwanted .orig files
提问by Akeem
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 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
.orig
extension.
If this variable is set tofalse
then this file is not preserved.
Defaults totrue
(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 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
.
git mergetool
使用“.orig
”后缀保存文件的合并冲突版本。
在添加和提交合并或添加*.orig
到您的.gitignore
.
Beriksuggests in the commentsto use:
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).
So you need to reset those settings as well.
因此,您还需要重置这些设置。
回答by CB Bailey
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
.
您必须小心使用,kdiff3
因为 whilegit mergetool
可以配置为.orig
在合并期间保存文件,默认行为kdiff3
是同时保存.orig
独立于git mergetool
.
You have to make sure that mergetool
backup 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 文件的选项
回答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 -r
if 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 -f
command but use git clean --dry-run
first 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:
视窗:
- in File
Win/Users/HOME/.gitconfig
setmergetool.keepTemporaries=false
- in File
git/libexec/git-core/git-mergetool
, in the functioncleanup_temp_files()
addrm -rf -- "$MERGED.orig"
within the else block.
- 在文件
Win/Users/HOME/.gitconfig
集中mergetool.keepTemporaries=false
- 在 File 中
git/libexec/git-core/git-mergetool
,在else 块中的cleanup_temp_files()
add函数中rm -rf -- "$MERGED.orig"
。