[英]In git how do you point the MASTER pointer(branch) to another commit without merging?
I was working off of master and made some bad commits C
& D
. 我当时是靠大师级的工作,并做出了一些糟糕的
C
& D
承诺。
A --- B --- C --- D (MASTER)
So I decided to restart the work from the known good commit B
because I thought it would be easier than to try and find the mistake inside the C
and/or D
commits. 因此,我决定从已知的良好提交
B
重新开始工作,因为我认为这比尝试在C
和/或D
提交中查找错误要容易得多。 But I also wanted the option of going back to D
if the new attempt didn't work out for whatever reason. 但是我也希望如果由于某种原因新的尝试没有奏效,可以选择返回
D
So I first created a detached HEAD pointing at B
and then created a new branch (RETRY). 因此,我首先创建了一个指向
B
的分离HEAD,然后创建了一个新分支(RETRY)。 My git repo now looks like this: 我的git repo现在看起来像这样:
A --- B --- C --- D (MASTER)
\
\
E --- F (RETRY)
As it turns out it was easier to just restart work at B
and my commit F
works wonderfully. 事实证明,只需重新开始
B
工作就更容易了,而我的提交F
工作非常出色。 So now my question is: how do I make MASTER point to F without merging with all the work done in C
and D
(but still keeping the C
and D
commits around in case I want to refer to them in the future)? 所以现在我的问题是:如何使MASTER指向F而又不与
C
和D
完成的所有工作合并(但仍保留C
和D
提交,以防将来我想引用它们)? I want to end up with: 我要结束于:
A --- B --- C --- D
\
\
E --- F (MASTER)
git checkout master
git branch old
git reset --hard retry
Will create (but not switch to) a new branch (called old
) which points to the same commit as master and then move master
to point to the same commit as retry
. 将创建(但不切换到)新分支(称为
old
),该分支指向与master相同的提交,然后将master
移至指向与retry
相同的提交。
First, create some branch, say old_master
to keep it as pointer to your failed work in master
: 首先,创建一个分支,说
old_master
,使其成为master
失败工作的指针:
git branch old_master master
Now, make master
point to F: 现在,将
master
点指向F:
git checkout master
git reset --hard F
Later, you can checkout to old_master
to see your old bad commits. 稍后,您可以签出到
old_master
以查看您的旧错误提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.