且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有整个分支的情况下仅对最后两个提交进行重新设置?

更新时间:2023-09-20 14:03:58

警告:以下git命令将重写feature分支的历史记录. git rebasegit reset是危险的,因为它会对使用feature分支的其他任何人造成严重破坏.

Warning: The following git commands will rewrite the history of the feature branch. git rebase and git reset are dangerous because it can wreak havoc for anyone else who is using the feature branch.

首先在与feature相同的提交中创建分支other_feature.

First create the branch other_feature at the same commit as feature.

git checkout -b other_feature feature

将前两次提交重新设置为master.

Rebase the previous two commits onto master.

git rebase --onto master HEAD~2

结帐feature.

git checkout feature

feature重置为所需的提交.

git reset --hard HEAD~2