【问题标题】:How to re-merge a file in the git?如何重新合并git中的文件?
【发布时间】:2011-06-22 04:44:49
【问题描述】:

我有 10 个文件在合并分支时发生冲突。我已经解决了 10 个文件的所有冲突(花了很长时间)。不幸的是,在提交之前,我发现一个文件被错误地合并了,需要重新开始这个文件。 :(

在Git中,如何将已合并的文件标记为未合并,即如何重新合并该文件?

【问题讨论】:

标签: git git-merge


【解决方案1】:
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

【讨论】:

  • +1 甜蜜!不知道-m的最后一件事。确实很有用!
  • @Magnus Skog:我用过一两次,所以我不得不翻遍手册页才能再次找到它。
  • 不错!我也不知道这个:)
  • 感谢您为我节省了这么多时间!
猜你喜欢
  • 2021-02-07
  • 2011-02-11
  • 2013-10-04
  • 2017-07-15
  • 1970-01-01
  • 1970-01-01
  • 2012-06-16
  • 2011-09-11
  • 1970-01-01
相关资源
最近更新 更多