如何在Git中完全用远程分支替换本地分支? [英] How to replace local branch with remote branch entirely in Git?
问题描述
我有两个分支:
- 本地分支机构(与我合作的分支机构)
- 远程分支(公共,只有经过充分测试的提交才可以进入那里)
最近我严重搞砸了当地分支机构.
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.
推荐答案
- Make sure you've checked out the branch you're replacing (from Zoltán's comment).
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屋!