我的同事昨天惹了点麻烦。他将master
移动到origin/master
后面大约100次提交(我不知道他是如何做到的,很可能是with this),然后他提交了。结果是,master
现在正在执行他的新提交,而上一次提交是origin/master
后面的100次提交。看起来是这样的:
master *
|
| * origin/master
| *
... ~one hundred commits below
| *
\ *
\
*
我对如何解决这个问题没有信心,所以我们所做的方法就是扔掉回购并再次克隆它。纠正这个错误的正确方法是什么?
他的目的是在hotfix
之前创建一个名为“origin/master
100提交”的新分支,并将这些更改提交给它。我觉得他根本不想搬master
。
我试着修一下这个:
git checkout master
git branch hotfix
#still on master
git reset --hard HEAD~1
git branch -f master <commit of origin/master>
发布于 2015-03-05 11:34:18
我只需创建一个名为hotfix
的分支,并将master
重置为origin/master
$ git checkout master
$ git branch hotfix
$ git reset --hard origin/master
发布于 2015-03-05 11:50:04
免责声明:我不是git专家。这是我能想到的最好的了。
首先,创建一个具有现有修补程序的新分支:
git checkout -b oops <commit-id>
然后,切换回主并删除所选的提交:
git checkout master
git rebase --onto <commit-id>^ <commit-id>
https://stackoverflow.com/questions/28885833
复制