如何在Git中完全用远程分支替换本地分支? [英] How to replace local branch with remote branch entirely in Git?

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

问题描述

我有两个分支:

  1. 本地分支机构(与我合作的分支机构)
  2. 远程分支(公共,只有经过充分测试的提交才可以进入那里)

最近我严重搞砸了当地分支机构.

Recently I seriously messed up my local branch.

我将如何用远程分支完全替换本地分支,以便可以从现在的远程分支继续工作?

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?

我已经搜索过SO,并且在本地签出到远程分支没有任何作用.

I have 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分支更新为与origin/master相同的修订版,并且--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.

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

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