Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git confusion - how to revert local changes to latest remote push?

Tags:

git

git-revert

I have a local git repository, but things get wrong and complicated and I simply want to overwrite all the files in my local directory with the latest version of what is on the remote repository. This would be like a clone, but for an already setup local git repository.

For example: if use git pull, then I don't get locally deleted folders back from the remote.

Is it checkout that I must use? But how to tell it to retrieve the files from a remote (and not from the stage) and overwrite all?

like image 332
user1738984 Avatar asked Oct 11 '12 17:10

user1738984


People also ask

How do I revert changes to my remote?

When you have pushed some commits to the remote repository and would like to undo those changes, you need to use the revert command to create a new commit, undoing all those changes. Note that history will not be rewritten in case of a revert.

How do I revert a commit locally remotely?

To undo the last commit from a remote git repository, you can use the git reset command. command. This will undo the last commit locally. command to force push the local commit which was reverted to the remote git repository.

How do I get rid of local changes?

There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.


1 Answers

You probably want to use git reset. Assuming you have done a git fetch recently, the following will discard everything in your local and reset it to the point you specify as the final argument (in this case the current HEAD of the origin/master remote tracking branch):

$ git reset --hard origin/master 
like image 71
Brian Phillips Avatar answered Sep 22 '22 22:09

Brian Phillips