[英]Git: Discard all changes on a diverged local branch
I have a local topic branch that's tracking a remote branch. 我有一个跟踪远程分支的本地主题分支。 For the sake of argument, say the commit histories look like this: 为了论证,请说提交历史如下:
A--B--C--O1--O2--O3 (origin/phobos)
\
L1--L2--L3 (phobos)
Having looked at the relative commit histories, I now want to discard all the changes to the local phobos
branch and get it back to being a direct copy of origin/phobos
, so that the local history looks like this: 看了相关的提交历史后,我现在想要放弃对本地phobos
分支的所有更改,并将其恢复为origin/phobos
的直接副本,以便本地历史记录如下所示:
A--B--C--O1--O2--O3 (phobos origin/phobos)
I really don't want the local changes to the phobos
branch, and I really don't want any merges to show up in the origin repository afterwards. 我真的不希望本地更改phobos
分支,我真的不希望任何合并后来在源存储库中显示。 (So, just merging isn't what I have in mind.) (所以,合并并不是我想到的。)
This seems like it should be really easy, but my google-fu has failed me. 这看起来应该很容易,但是我的google-fu让我失望了。 How do I do this? 我该怎么做呢?
git checkout phobos
git reset --hard origin/phobos
This tells Git to reset the head of phobos
to the same commit as origin/phobos
, and to update the working tree to match. 这告诉Git将phobos
的头重置为与origin/phobos
相同的提交,并更新工作树以匹配。
Delete the branch, then re-create it: 删除分支,然后重新创建它:
$ git branch -D phobos
$ git checkout --track -b phobos origin/phobos
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.