【问题标题】:Hard reset a remote branch to a few commits behind [duplicate]将远程分支硬重置为 [重复] 后面的几个提交
【发布时间】:2018-02-28 02:11:37
【问题描述】:

我将本地 develop 分支重置为后面的几个提交,并希望将本地 develop 分支推送到其远程,以便远程的 HEAD 现在也重置为后面的几个提交。

换句话说,我确实喜欢这样:

UserName path/ (develop)
$ git reset --hard {CommitIdOfAFewCommitsBehind}
Your branch is behind 'origin/develop' by 14 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working tree clean


$ git push origin develop
To https://github.devtools.merrillcorp.com/Javelin/wopi-poc.git
 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://github/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

如何让遥控器也转到我想要的提交 ID?

【问题讨论】:

    标签: git


    【解决方案1】:

    当您硬重置 develop 分支时,您重写了该分支的历史记录。这样做的一个副作用(稍后讨论的另一个副作用)是 Git 不能再仅仅接受来自您的推送,因为它不知道如何将您的新截断分支与远程版本链接。所以,你需要强制 push 覆盖:

    git push --force origin develop
    

    我提到了另一个副作用,即重写 develop 的历史也会给团队中的其他任何人带来问题,当他们拉动时,他们恰好共享这个分支。

    大多数时候,对于共享分支,最好使用git revert,而不是通过硬重置来核对提交。查看文档或 Stack Overflow 以了解如何恢复一系列提交。

    【讨论】:

    • 9 分钟到绿色检查。
    猜你喜欢
    • 2015-05-08
    • 2011-08-14
    • 1970-01-01
    • 2018-07-04
    • 2021-09-23
    • 2020-07-29
    • 1970-01-01
    • 2018-11-01
    • 2018-10-01
    相关资源
    最近更新 更多