Git: How to return my local branch to the remote branch state?

I messed up my local project branch and I want to return my local copy to a remote state. How do I understand this goal?

+4
source share
5 answers

you can reset with

git reset --hard HEAD

you will lose all your changes if you do. This may be helpful .

+2
source

If you are not afraid of losing any local history, you can switch to another branch and then delete the local branch and then check the remote version. For example, if you want to return a branch named "test_feature", you can do this:

 $ git checkout master $ git branch -D test_feature # see note about -D below $ git checkout test_feature # should track origin/test_feature 

NOTE. -D will force the branch to be deleted and will suppress warnings about unrelated changes.

This is useful if you merged a branch that you did not intend, because the HEAD pointer may change depending on the type of merge.

EDIT . Another way to do the same: just type:

 git reset --hard origin/test_feature 

This will reset the branch that you are currently in to the state of the remote (in this case) branch of test_feature .

@hvgotcodes has a variant of this in his example (he aims to commit HEAD)

+8
source

This is how you "return [your] local copy to the remote state":

 # get the latest from remote repo git fetch origin # set current branch to exact state of remote branch git reset --hard origin/my_branch_name 
+1
source

There is just one airliner to do what you ask, but usually when it seems to me that I have "mixed up the branch" and that on the remote control, I use interactive reboot, which gives me a little more control. That way, I can edit the commit if necessary, or delete the lines if I just don't need the commit. See here: http://book.git-scm.com/4_interactive_rebasing.html

0
source

If you want to revert to the remote LAST version :

 git fetch --all git reset --hard origin/master 

If you want to return to a specific version :

First enter a line that identifies the commit on some day, doing:

 git rev-list -n 1 --before="2009-07-27 13:37" origin/master 

it prints the commit identifier, takes a string (e.g. XXXX) and does:

 git checkout XXXX 
0
source

Source: https://habr.com/ru/post/1402739/


All Articles