本地分支从Origin分支分离出来,但我不想合并/ fastforward [英] Local branch diverged from Origin branch but I do not want to merge/fastforward

查看:242
本文介绍了本地分支从Origin分支分离出来,但我不想合并/ fastforward的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个提交已经被推送到原始分支。这些提交包含导致问题的代码。为了解决这个问题,我在问题开始之前做了一个 git reset --hard< sha> 的提交。



我已经解决了问题并在本地提交。现在我想推到Origin,但是我不能这样做,因为我的分支是由5次提交(导致问题)和1次提交(修复提交)提前后面的Origin。即。分支分支。



我不想合并来自Origin的任何更改。我怎样才能将Origin的头部设置为我的本地提交的头部,而不需要合并到我的本地分支中的分离提交?



谢谢!

解决方案

干净的方式(保留历史记录) 在您当前的提交中使用本地bugfix分支

  • 结帐主文件(或任何源文件)并将其快速转发到已损坏的远程头文件 code> git revert 糟糕的提交(在你分叉的最后一个good sha 和远程HEAD之间的所有内容)......这样可以在保留时删除不需要的更改所有的历史

  • 将您的bugfix分支合并到master中:现在所有master的更改都已被恢复,这将是一次简单的合并。 b

    肮脏的方式(丢弃历史记录,discombobulate在远程分支上工作的任何人)


    1. 只需使用 git push -f (仔细检查你是否有正确的选项和放大器) refspec),并希望没有其他人的远程分支历史发生变化。


    Several commits have been pushed to the origin branch. These commits contain code that caused a problem. In order to fix the problem I did a git reset --hard <sha> to the commit before the problem started.

    I have since fixed the problem and committed locally. Now I want to push to Origin but I cannot because my branch is behind Origin by 5 commits (that caused the problem) and ahead by 1 commit (the fixing commit). ie. diverged branches.

    I do not want to merge in any of the changes from Origin. How can I set the head of Origin to that of my Local commit and without merging in the breaking commits into my Local branch?

    Thanks!

    解决方案

    The clean way (that preserves history)

    1. create a local bugfix branch at your current commit
    2. checkout master (or whatever the origin is) and pull it fast-forward to the broken remote HEAD
    3. git revert the bad commits (everything between the last good sha where you forked, and the remote HEAD) ... this removes the unwanted changes while preserving all the history
    4. merge your bugfix branch onto master: now all master's changes have been reverted, this will be an easy merge

    The dirty way (discards history, discombobulates anyone else working on the remote branch)

    1. just use git push -f (double-check you have the right options & refspec) and hope no-one else has had their remote branch history change underneath them

    这篇关于本地分支从Origin分支分离出来,但我不想合并/ fastforward的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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