git - 覆盖并推送 Git 分支

标签 git

在将我的更改 merge 到上游 master 时,我经常发现自己在做以下事情:

git checkout somefeature
git checkout -b integration
git rebase master # resolving conflicts along the way
git checkout somefeature
git merge integration # or rebase, doesn't matter in this example

我经常会发现,将集成分支 merge 回我的功能分支会导致某些冲突失败。我的第一个问题是,“如果我的集成分支是某个功能的后代并且我已经解决了与上游主节点的冲突,为什么会发生这种情况?”

如果您想知道为什么我一开始就使用集成分支,那是为了防止半失败的 merge 污染我当前的分支。

我目前的解决方法是:

git checkout integration
git branch -f somefeature # overwrite the branch

现在的问题是我无法将更改推送回远程分支:

git push origin somefeature
! [rejected]        somefeature -> somefeature (non-fast forward)

所以现在我必须删除远程分支并重新推送我的更改。这不是执行此操作的最佳方法,所以我想知道,“覆盖分支并将更改推送到远程分支的最佳方法是什么?”

最佳答案

问题是因为 git rebase 生成了一系列新的提交,这些提交不是 somefeature 分支的后代,然后当您尝试将它们 merge 回 somefeature 在 rebase 期间完成的冲突解决不适用。如果您只是 merge 而不是 rebase ,那么这将起作用,因为 merge 提交somefeature 分支下降。

就推送到远程分支而言,您可以使用 --force 来使推送成功,但这会给拥有它副本的任何其他人带来问题。

关于git - 覆盖并推送 Git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4740985/

相关文章:

Eclipse Git 关键字扩展

git commit 命令与 core.editor 等于atom

git - github web界面中的绿色文件夹图标是什么意思?

git - GitHub : "remote: This repository moved. Please use the new location" 中重命名的 repo 出错

git - "git clean -f"不留下空目录

git - 如何防止 phabricator 吃掉我的提交历史

c# - 拒绝为 C# (Unity) 推送基于 Git 提交代码的样式检查?

git - 此存储库已超过其数据配额。负责LFS带宽的账号应该购买更多的数据包来恢复访问

bash - 为什么 Jenkins 胜过简单的 bash 脚本?

git - 如何在 jenkins 中针对 master 分支运行 git diff-tree?