我犯了一个错误,为了将我的分支与它所基于的分支的最新版本合并在一起,我做了一次rebase。我之所以说“错误”,是因为我没有意识到以后会更加困难(例如,git pull会导致本应没有冲突的重大冲突,而git push需要暴力)。
这就是我到目前为止所做的:
$ git checkout major_branch
$ git pull
$ git checkout my_branch
make some changes and commits.
$ git rebase major_branch
make some changes and commits.
$ git push --force 现在,我需要从major_branch (再次)获取最新的更改。除了我之外,没有人从事过my_branch的工作。
我如何才能做到这一点而不带来灾难呢?
也就是说,我可以多次改变基址吗?
我可以回到合并并放弃rebasing吗?
这条路对吗?
$ git checkout major_branch
$ git pull // does this only pull major_branch, or all branches from origin?
$ git checkout my_branch // my_branch exists locally and on origin. what if they are different?
$ git merge major_branch // is this the correct "way round"?
$ git push --force . // push my_branch back to server in case my local machine dies.如果作为我的"parent“的major_banch变得过时,现在每个人都在使用"major_branch2",我有什么选择呢?我能简单地做"git rebase major_banch2“吗?
在某些时候,我需要将我的更改放回major_branch中。我该怎么做呢?我可以这样做吗:
$ git checkout major_branch
$ git pull // does this only pull major_branch?
$ git merge my_branch // is this the correct "way round"?
fix merge conflicts
$ git commit
$ git push // do I need to force?作为另一种选择,有没有办法摆脱我目前的改变基数的情况?例如,我有我的个人功能分支,包括我的所有更改,以及来自major_banch的所有更改,但不是重新建立基础,这样我就可以简单地使用合并、拉入和推送(即“正常”工作流)?
发布于 2019-05-01 18:02:50
你可以想改多少次就改多少次。当您使用git pull时,仅影响当前分支。因此,在git pull之后的git checkout major_branch将从远程获取并合并major_branch。然后,您可以签出my_branch并执行git rebase major_branch。这几乎是使用私有WIP分支的标准方式,其他人都没有在使用它。执行此操作时,您将始终需要强制推送my_branch。
如果您更喜欢重新设置my_branch的基数并强制推送,则不需要将major_branch合并到my_branch中。只有当几个人在my_branch上工作时才需要它,因此强制推送将不是一个选项。
因此,如果你只是在一个分支上工作,那么在需要的时候改变它的基址并强制推送它。如果其他人正在处理分支,则将主分支合并到其中并执行正常推送。
https://stackoverflow.com/questions/55934081
复制相似问题