【问题标题】:How to resolve git status "Unmerged paths:"?如何解决 git status “未合并的路径:”?
【发布时间】:2011-03-13 12:44:16
【问题描述】:

我将分支dog 合并到animal。当我去提交时,我得到以下信息:

Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution
both deleted:       ../public/images/originals/dog.ai
added by them:      ../public/images/original_files/dog.ai

我在每个分支中都有不同的目录名和文件名。 animal 分支有我想要的更改。

当我去重置头部时,它不起作用。当我执行任何其他 git 操作(删除、结帐等)时,我会收到 path not found 错误。

我需要执行什么命令来解决这个问题?

【问题讨论】:

    标签: git merge git-merge git-status


    【解决方案1】:

    您需要做的就是:

    # if the file in the right place isn't already committed:
    git add <path to desired file>
    
    # remove the "both deleted" file from the index:
    git rm --cached ../public/images/originals/dog.ai
    
    # commit the merge:
    git commit
    

    【讨论】:

    • 进一步的解释会派上用场
    【解决方案2】:

    如果您的文件已经签入,并且您的文件已被合并(但未提交,因此合并冲突被插入到文件中),另一种处理这种情况的方法是运行:

    git reset
    

    这将切换到 HEAD,并告诉 git 忘记任何合并冲突,并保持工作目录不变。然后您可以编辑有问题的文件(搜索“更新的上游”通知)。处理完冲突后,您可以运行

    git add -p
    

    这将允许您以交互方式选择要添加到索引的更改。一旦索引看起来不错(git diff --cached),您可以提交,然后

    git reset --hard
    

    销毁工作目录中所有不需要的更改。

    【讨论】:

    • 什么是"Updated upstream" notices
    • @takias:每个文件中的标记类似于:&lt;&lt;&lt;&lt;&lt;&lt;&lt; [branch] \n [content] \n ==== \n [content] \n [branch] &gt;&gt;&gt;&gt;&gt;&gt;&gt;。我认为自从我写这篇文章以来,格式可能略有变化,但请参阅 wincent.com/wiki/Git_merge_conflict_cheatsheet 示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 2015-10-15
    相关资源
    最近更新 更多