在冲突的 git 合并后清理?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15373928/
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-19 08:18:38  来源:igfitidea点击:

Cleaning up after a conflicted git merge?

gitversion-controlmergemerge-conflict-resolutionfilemerge

提问by Craig Otis

I had a small conflict in a .hheader file in a project I'm working on. This project is tracked in Git.

.h正在处理的项目中的头文件中存在小冲突。该项目在 Git 中进行跟踪。

Fortunately, the conflict was very simple to solve. I used

幸运的是,冲突很容易解决。我用了

git mergetool

git mergetool

And chose the default (opendiff) which seemed to be FileMerge on my Mac. I made the appropriate changes, saved the file, and closed.

并选择了默认 ( opendiff),它在我的 Mac 上似乎是 FileMerge。我进行了适当的更改,保存了文件,然后关闭了。

Git then asked me if the merge was successful, I said yes:

Git然后问我合并是否成功,我说是:

Was the merge successful? [y/n] y

Was the merge successful? [y/n] y

But now, I have:

但现在,我有:

> git st
# On branch develop
# Changes to be committed:
#   modified:   MyHeader.h
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   MyHeader.h.BACKUP.52920.h
#   MyHeader.h.BASE.52920.h
#   MyHeader.h.LOCAL.52920.h
#   MyHeader.h.REMOTE.52920.h
#   MyHeader.h.orig

Which of those extra junk conflict files were created by FileMerge, and which by Git?

哪些额外的垃圾冲突文件是由 FileMerge 创建的,哪些是由 Git 创建的?

And more importantly:How do I remove them?

更重要的是:我如何删除它们?

回答by Neil Forrester

You can simply delete them like you would any other file. For example:

您可以像删除任何其他文件一样简单地删除它们。例如:

rm MyHeader.h.orig

Alternatively, if there are no other untracked files, then after you commit with

或者,如果没有其他未跟踪的文件,则在您提交后

git commit -a

you may clean your repository with

你可以用

git clean -n
git clean -f

git clean -nwill tell you what git clean -fwill do, so you can be sure it's what you want.

git clean -n会告诉你git clean -f会做什么,所以你可以确定这是你想要的。

回答by Ben Lings

If they are the only untracked files, you can use git cleanto delete them. Run it once with the -nflag to see what will be deleted then if you are sure, run it with -f. Don't use it if you have untracked files you want to keep!

如果它们是唯一未跟踪的文件,您可以使用git clean删除它们。使用-n标志运行一次以查看将删除的内容,然后如果您确定,请使用-f. 如果您要保留未跟踪的文件,请不要使用它!

回答by Brent Faust

First commit your merge.

首先提交您的合并。

Once you're satisfied that all is well, simply remove these extra files manually (using rm <filename>, for example).

一旦您对一切正常感到满意,只需手动删除这些额外的文件(rm <filename>例如,使用 )。