如何重新合并git中的文件?

时间:2011-06-22 04:44:49

标签: git git-merge

我有10个文件在合并分支时有冲突。我已经解决了10个文件的所有冲突(花了很长时间)。不幸的是,在提交之前,我发现一个文件合并错误,需要再次启动此文件。 :(

在Git中,如何标记已合并的文件,换句话说,如何重新合并那个文件?

1 个答案:

答案 0 :(得分:36)

git checkout -m <filename>

这将从索引中删除它,并恢复为“冲突”文件,该文件具有随后进行合并所需的所有标记。

从git help checkout手册页:

-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