使用git将分支重置为远程状态

Every once in a while I accidentally hose my repository's master branch by merging or committing something I shouldn't.  And then on rare occasion I push that to my remote and then things get all sorts of messed up.  Every PR from that point on has some wonky commits and I look like a noob.  Sometimes the best course of action is to just reset to the a remote branch's master (i.e. the repository I forked the project from) and get on with life that way.  Here's how to do so:

我偶尔不时地通过合并或提交不应执行的操作来管理存储库的master分支。 然后在极少数情况下,我会将其推送到我的遥控器,然后事情变得一团糟。 从那时起,每个PR都有一些奇怪的提交,而我看起来像个菜鸟。 有时,最好的做法是将其重置为远程分支的主服务器(即,我从其分支项目的存储库),然后继续这种方式。 这样做的方法如下:


git fetch some-remote   # "origin" if you want to use your own branch
git reset --hard some-remote/master


The first step is fetching a list of branches from the remote.  The next is executing a hard reset of the branch based on the remote.

第一步是从远程获取分支列表。 下一步是基于远程执行分支的硬重置。

Now you can stop asking yourself how things got so messed and up can get back to business!

现在,您可以停止问自己,事情如何变得如此混乱,而一切又可以恢复正常!

翻译自: https://davidwalsh.name/reset-branch-remote

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值