【问题标题】:Git merge did not merge, just added all commits to masterGit合并没有合并,只是将所有提交添加到master
【发布时间】:2017-01-09 20:54:46
【问题描述】:

我将一个分支合并回 master 并且没有合并提交,来自另一个分支的所有提交现在看起来好像它们已提交给 master。

我做了什么:

在 SourceTree 中,我选择了 master,选择了 merge,选择了最近的提交并将其合并。它表明我需要推送我的 39 次提交,所以我做到了。直到那时我才意识到没有合并提交。

我怎样才能扭转这种局面?提交显示好像它们都在掌握中,这很尴尬。

【问题讨论】:

    标签: git merge atlassian-sourcetree


    【解决方案1】:

    如果可以在没有合并提交的情况下合并分支,则默认是这样做的。这被称为“快进”,HEAD 标记只是移动到新的提交。不会生成新的提交。

    如果您不想这样做,可以使用--no-ff 强制合并提交。

    git merge --no-ff <refspec>
    

    来自git-merge 手册页:

       --ff
           When the merge resolves as a fast-forward, only update the branch
           pointer, without creating a merge commit. This is the default
           behavior.
    
       --no-ff
           Create a merge commit even when the merge resolves as a
           fast-forward. This is the default behaviour when merging an
           annotated (and possibly signed) tag.
    
       --ff-only
           Refuse to merge and exit with a non-zero status unless the current
           HEAD is already up-to-date or the merge can be resolved as a
           fast-forward.
    

    【讨论】:

    • 谢谢,我很惊讶,因为我所有的其他合并都没有这样做。但是,我怎样才能扭转这种快进?
    • @DouglasGaskell 要撤消它,请转到您合并到的分支,使用 git log 找到旧的 HEAD 提交的 ID,然后重置为那个。 git reset --hard &lt;old_HEAD&gt;。然后用--no-ff 重新合并。请注意,git reflog 可能是查找旧哈希 ID BTW 的更快方法。那里的先前状态(最上面的状态)可能就是它。
    • @DouglasGaskell 我刚刚意识到您在 SourceTree 中而不是使用命令行。你仍然可以这样做,但我不知道如何在 SourceTree 中做到这一点。
    • 发现我可以将分支重置到某个点,然后用命令行进行强制推送。哪个有效
    猜你喜欢
    • 2018-12-24
    • 1970-01-01
    • 2020-05-04
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2012-01-05
    相关资源
    最近更新 更多