git 变基后清理分支
Cleanup branch after git rebase
我通常在 Git 方面相当有能力,但我不太确定在这种情况下发生了什么,以及什么是最好的解决方案。
场景:
- 我从 dev 创建了一个功能分支。
- 修复已完成、测试并推送。
- 然后我切换回开发,执行
git pull
并看到我的队友的几个提交。
git checkout featureBranch
后跟 git rebase dev
以重播我对最新开发者的更改(据我所知)。
git status
表示本地和原始 featureBranch 已经分歧 git pull
是必需的。
git pull
导致提交消息终端打开。
git status
显示 git push
是必需的。
- 在
git push
之后,我的 PR 显示了我分支上来自 dev 的同事的所有提交,而不仅仅是修复。
在这种情况下我做错了什么?我想继续单独处理我的 featureBranch 直到它被修复,然后确保应用我的更改到最新的开发者以避免冲突。在这种情况下,我的团队鼓励变基。
为什么来自 dev 的新提交显示在我的 PR featureBranch >> dev 中,而它们已经在 dev 上了?
将我的 PR 恢复到第一个原始提交的最佳解决方案是什么? 我不是说压缩在这里,我的意思是开发提交不应该在这里。
What did I do wrong in this case?
第二个git pull
。一旦你重新定位,git status
预计会告诉你你已经偏离。
但是你应该从那里强制推送 (git push --force
),用一个新的替换你的 PR 分支的远程历史。
如果您是唯一一个从事该 PR 的人,则尤其如此。
git status says that local and origin featureBranch have diverged git pull is required.
当你变基时,你实际上是在改变你的分支的历史。此历史记录将不同于 origin
处的历史记录,但这很好,因为这是您想要的。您在这一步可能应该做的是强制将 运行 push -f
推送到 origin/yourFeatureBranch
.
git status says that local and origin featureBranch have diverged git pull is required.
这是预料之中的,因为与原始版本(上游跟踪)相比,您已经重写了本地分支历史记录。
git pull results in a commit message terminal opening.
是的,您在这里想要做的是 而不是 进行拉取,然后在本地合并,或者强制向上游推送以在远程中反映您的 rebased 分支版本。通过拉动你然后将原始历史再次合并到你的变基历史中,这违背了变基的目的。
What did I do wrong in this case? I wanted to stay working on my featureBranch in isolation until it was fixed, and at that point, make sure my changes were applied to the latest dev to avoid conflicts. In this case my team encourages rebase.
(在你的情况下)你所做的 "wrong" 是在 rebase 后再次拉动分支。您应该小心地强制推送(例如 git push myremote mybranchname --force
)。如果你养成了在强制推送时总是指定远程和分支名称的习惯,你就不太可能覆盖你没想到的东西。
Why are the new commits from dev showing in my PR featureBranch >> dev when they are already on dev?
因为您重新设置了基准,但随后通过将原始版本拉回重新设置基准的版本搞乱了分支历史记录。您应该期望成功的 rebase 仅在拉取请求中显示 您的 提交。
What would be the best solution to bring my PR back to the 1 original commit? I don't mean squash here, I mean the dev commits should not be here.
如果自从您上次推送到您的遥控器后,您除了变基外没有做任何更改,我建议您再次重置和变基:
git reset --hard yourremote yourbranchname
git rebase devbranch
git push yourremote yourbranchname --force
希望对您有所帮助。
我通常在 Git 方面相当有能力,但我不太确定在这种情况下发生了什么,以及什么是最好的解决方案。
场景:
- 我从 dev 创建了一个功能分支。
- 修复已完成、测试并推送。
- 然后我切换回开发,执行
git pull
并看到我的队友的几个提交。 git checkout featureBranch
后跟git rebase dev
以重播我对最新开发者的更改(据我所知)。git status
表示本地和原始 featureBranch 已经分歧git pull
是必需的。git pull
导致提交消息终端打开。git status
显示git push
是必需的。- 在
git push
之后,我的 PR 显示了我分支上来自 dev 的同事的所有提交,而不仅仅是修复。
在这种情况下我做错了什么?我想继续单独处理我的 featureBranch 直到它被修复,然后确保应用我的更改到最新的开发者以避免冲突。在这种情况下,我的团队鼓励变基。
为什么来自 dev 的新提交显示在我的 PR featureBranch >> dev 中,而它们已经在 dev 上了?
将我的 PR 恢复到第一个原始提交的最佳解决方案是什么? 我不是说压缩在这里,我的意思是开发提交不应该在这里。
What did I do wrong in this case?
第二个git pull
。一旦你重新定位,git status
预计会告诉你你已经偏离。
但是你应该从那里强制推送 (git push --force
),用一个新的替换你的 PR 分支的远程历史。
如果您是唯一一个从事该 PR 的人,则尤其如此。
git status says that local and origin featureBranch have diverged git pull is required.
当你变基时,你实际上是在改变你的分支的历史。此历史记录将不同于 origin
处的历史记录,但这很好,因为这是您想要的。您在这一步可能应该做的是强制将 运行 push -f
推送到 origin/yourFeatureBranch
.
git status says that local and origin featureBranch have diverged git pull is required.
这是预料之中的,因为与原始版本(上游跟踪)相比,您已经重写了本地分支历史记录。
git pull results in a commit message terminal opening.
是的,您在这里想要做的是 而不是 进行拉取,然后在本地合并,或者强制向上游推送以在远程中反映您的 rebased 分支版本。通过拉动你然后将原始历史再次合并到你的变基历史中,这违背了变基的目的。
What did I do wrong in this case? I wanted to stay working on my featureBranch in isolation until it was fixed, and at that point, make sure my changes were applied to the latest dev to avoid conflicts. In this case my team encourages rebase.
(在你的情况下)你所做的 "wrong" 是在 rebase 后再次拉动分支。您应该小心地强制推送(例如 git push myremote mybranchname --force
)。如果你养成了在强制推送时总是指定远程和分支名称的习惯,你就不太可能覆盖你没想到的东西。
Why are the new commits from dev showing in my PR featureBranch >> dev when they are already on dev?
因为您重新设置了基准,但随后通过将原始版本拉回重新设置基准的版本搞乱了分支历史记录。您应该期望成功的 rebase 仅在拉取请求中显示 您的 提交。
What would be the best solution to bring my PR back to the 1 original commit? I don't mean squash here, I mean the dev commits should not be here.
如果自从您上次推送到您的遥控器后,您除了变基外没有做任何更改,我建议您再次重置和变基:
git reset --hard yourremote yourbranchname
git rebase devbranch
git push yourremote yourbranchname --force
希望对您有所帮助。