更改新 git 分支的开始提交

Changing the starting commit of a new git branch

我忘记在创建新分支之前执行 pull。没认出来,做了功课和整理merge。现在我看到新的(现在合并的)分支的起点是错误的,因为它过去太远了。

是否可以更正?

假设历史包含两个分支 - mastertopictopic 是您在未执行 git pull.

的情况下从 master 创建的分支
git reset --merge ORIG_HEAD  // Undo git-merge
git checkout master
git pull
git rebase master topic  // Replay commits of topic on new master

在此之后您可以继续合并(如果需要)。


有关撤消 git-合并的更多详细信息,请参阅 here