如何重新合并git中的文件? [英] How to re-merge a file in the git?

查看:397
本文介绍了如何重新合并git中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个合并分支时有冲突的文件。我解决了10个文件中的所有冲突(耗时很长)。不幸的是,在提交之前,我发现一个文件已被合并错误,需要重新启动该文件。 :



在Git中,如何标记已合并的文件未合并,换句话说,如何重新合并该文件? b $ b'的div类= h2_lin>解决方案

  git的结帐-m<文件名> 

这将从索引中删除它,然后恢复为冲突文件,该文件具有完成合并所需的所有标记。



从git帮助结帐手册页:

  -m,--merge 
在切换分支时,如果对当前分支与切换到的分支之间的一个或多个文件进行本地修改,则该命令拒绝切换
分支以保留您的修改。但是,使用此选项,当前分支,工作树内容和新分支之间的三向合并完成,并且
将在新分支上。

当合并冲突发生时,索引条目f或冲突的路径没有被合并,你需要解决冲突并用git add(或者git rm,如果合并应该是
导致删除路径)标记已解决的路径。

当从索引检出路径时,使用此选项可以在指定的路径中重新创建冲突的合并。

(最后一句是最重要的一句)。

以下是一篇博客文章,介绍为什么添加它以及旧版git无法实现的功能: http: //gitster.livejournal.com/43665.html


I have 10 files which have conflicts when merging branches. I've resolved all conflicts of the 10 files(took long time). Unfortunately before the commit, I find out that one file has been merged wrong and need start again for this file. :(

in the Git, How to mark the file which has been merged unmerged, in other word, how to re-merge that one file?

解决方案

git checkout -m <filename>

This will remove it from the index, and revert back to a "conflicted" file that has all of the markers required to then do a merge.

From the git help checkout man page:

-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.

(The last sentence is the most important one).

Here is a blog post that describes why it was added and how it is not possible with older versions of git: http://gitster.livejournal.com/43665.html

这篇关于如何重新合并git中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆