git rebase [branch] AT 入口点

git rebase [branch] AT entry point

我当前的本地分支有 10 个提交:

我想做 git rebase other-branch 但我不想把它放在 "oldest commit" 中,意思是我不希望它在 "Commit 1".

之前出现

我想把它放在最近一次提交之前,所以在git rebase other-branch之后会有

我认为这是可能的,因为我们可以使用 git rebase -i 来移动提交顺序。

这将重写您分支的历史记录,但您可以通过以下方式完成此操作:

git reset --hard COMMIT9SHA
git merge other-branch
git cherry-pick COMMIT10SHA

如果你想避免合并提交,你可以先切换到 other-branch 并将其重新设置为 COMMIT9SHA:

git checkout other-branch
git rebase COMMIT9SHA