gpt4 book ai didi

rebase 后远程的 Git 分支

转载 作者:太空狗 更新时间:2023-10-29 14:32:08 25 4
gpt4 key购买 nike

我遇到了 git 的问题。我想在本地和远程的 master 上 rebase 一个分支 hotfix,所以这就是我所做的。

git checkout hotfix
git pull hotfix #just getting someone changes
git fetch origin master
git rebase origin/master

经过很长时间的解决冲突和重建项目,我让它工作正常,所以我必须将更改上传到远程分支。

git push origin hotfix

这是 git 认为的:

$ git push origin login2
To https://name@bitbucket.org/***/***.git
! [rejected] hotfix -> hotfix (non-fast-forward)
error: failed to push some refs to 'https://name@bitbucket.org/***/***.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.

我试过:

git pull --rebase

但这会产生与另一个 rebase 之前相同的冲突,它不应该。

我知道我总能做到:

git push -f

但我宁愿避免强制推送,因为我和另一个人一起工作。我想知道我做错了什么。我以为就是这样。

PD。我运行了 gitk,似乎没有对远程 origin/hotfix 的引用,只有本地 hotfix 出现了。

谢谢!

编辑: 我猜想当我对分支更改的最后一次提交进行 rebase 以应用 rebase 更改时,这就是它具有另一个 sha1 提交 ID 的原因。我 pull 覆盖了我的本地文件。

git pull --strategy=ours origin hotfix

最佳答案

关于 rebase 你需要知道的一件事是:

Git 将更改不属于新基本分支的每个提交的 SHA 哈希值。

这意味着在您对本地分支进行 rebase 后,总会与上游分支发生冲突,唯一的解决方法是强制推送到您的上游。

通常的做法是不对已推送到上游的提交进行 rebase 。如果只有一个人在一个分支上工作,那么 rebase 仍然可以

在这种情况下,您别无选择,只能用力 push 。将来,建议将您和您的合作者的工作分支分开,并混合使用 rebase 和 merge 策略来共享您的工作

关于 rebase 后远程的 Git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34502777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com