Git:放弃分散的本地分支上的所有更改 [英] Git: Discard all changes on a diverged local branch

查看:222
本文介绍了Git:放弃分散的本地分支上的所有更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个跟踪远程分支的本地主题分支。为了争辩,说提交历史是这样的:

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)

查看了相关的提交历史记录后,我现在想丢弃对本地 phobos 分支的所有更改,并将其恢复为直接 origin / 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:

A--B--C--O1--O2--O3 (phobos origin/phobos)

我真的不希望对 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. (So, just merging isn't what I have in mind.)

这看起来应该很容易,但我的google-fu已经让我失望了。

This seems like it should be really easy, but my google-fu has failed me. How do I do this?

推荐答案

删除分支,然后重新创建它:

Delete the branch, then re-create it:

$ git branch -D phobos
$ git checkout --track -b phobos origin/phobos

这篇关于Git:放弃分散的本地分支上的所有更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆