我意识到我必须先创建一个分支,但已经做了2次提交。好的,我找到了这个post分支,从以前的Git提交,并创建了一个新的分支,从prev-prev提交使用以下命令:
git checkout -b branch-name commit-id
git push origin branch-name
但是当我回头看GitHub时,我看到主仍然有2个最后的提交(我希望它们只在一个分支中)。
我该怎么做才能在master中删除它们,而在branch中保留它们?
乌利希期刊指南
- 恢复到前一次提交
git reset --hard commit
git push
--force origin master
或者更短,用 : 假设你是唯一一个在仓库工作的人,这将重置远程(GitHub)分支到你想要的。git switch master
git reset --hard <past_commit>
git switch -C
git switch -C master <past_commit>
git push --force