完全替换本地分支与远程分支 [英] Replace local branch with remote branch entirely

查看:87
本文介绍了完全替换本地分支与远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支:

I have two branches:


  1. 本地分支(与我一起工作的分支)

  2. 远程分支(公共的,只有经过良好测试的提交去那里)

最近我严重搞砸了我的本地分支(猜测每个git-新手一直在我的位置上)

Recently I seriously messed up my local branch (guess every git-newbie has been on my place at some point of time)

我如何将远程分支完全替换为本地分支,这样我就可以继续从远程分支是现在吗?

How would I replace the local branch entirely with the remote one, so I can continue my work from where the remote branch is now?

(我已经搜索过并检出到远程分支本地没有任何影响)

(I already searched SO and checking out to the remote branch locally does not have any effect)

推荐答案


  1. 确保你已经签出了你正在替换的分支(来自Zoltán的
  1. Make sure you've checked out the branch you're replacing (from Zoltán's comment).
  2. Assuming that master is the local branch you're replacing, and that "origin/master" is the remote branch you want to reset to:

git reset --hard origin/master


这会将您的本地HEAD分支更新为与原始/主版本相同的版本,并且 - hard 会将此更改同步到索引和工作区中。

This updates your local HEAD branch to be the same revision as origin/master, and --hard will sync this change into the index and workspace as well.

这篇关于完全替换本地分支与远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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