我有10个文件在合并分支时冲突。我已经解决了这10个文件的所有冲突(花费了很长时间)。不幸的是,在提交之前,我发现一个文件被错误地合并了,需要重新开始处理该文件。 :(
在Git中,如何标记已合并的文件未合并,换句话说,如何重新合并该文件?
git checkout -m <filename>
这将从索引中删除它,并恢复为一个“冲突”的文件,该文件具有执行合并所需的所有标记。-m, --merge
When switching branches, if you have local modifications to
one or more files that are different between the current
branch and the branch to which you are switching, the command
refuses to switch branches in order to preserve your
modifications in context. However, with this option, a
three-way merge between the current branch, your working tree
contents, and the new branch is done, and you will be on the
new branch.
When a merge conflict happens, the index entries for
conflicting paths are left unmerged, and you need to resolve
the conflicts and mark the resolved paths with git add (or git
rm if the merge should result in deletion of the path).
When checking out paths from the index, this option lets you
recreate the conflicted merge in the specified paths.
(最后一句话是最重要的)
这里有一篇博客文章,描述了为什么添加了这个功能以及在较旧版本的Git中如何不可能实现:http://gitster.livejournal.com/43665.html