Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert to origin's master branch's version of file

Tags:

git

I'm in my local computer's master branch of a cloned master-branch of a repo from a remote server.

I updated a file, and I want to revert back to the original version from the remote master branch.

How can I do this?

like image 737
mrblah Avatar asked Nov 30 '09 03:11

mrblah


People also ask

How do I revert to a previous version of a file in git?

To move HEAD around in your own Git timeline, use the git checkout command. There are two ways to use the git checkout command. A common use is to restore a file from a previous commit, and you can also rewind your entire tape reel and go in an entirely different direction.


3 Answers

Assuming you did not commit the file, or add it to the index, then:

git checkout -- filename

Assuming you added it to the index, but did not commit it, then:

git reset HEAD filename
git checkout -- filename

Assuming you did commit it, then:

git checkout origin/master filename

Assuming you want to blow away all commits from your branch (VERY DESTRUCTIVE):

git reset --hard origin/master
like image 92
gahooa Avatar answered Oct 17 '22 09:10

gahooa


I've faced same problem and came across to this thread but my problem was with upstream. Below git command worked for me.

Syntax

git checkout {remoteName}/{branch} -- {../path/file.js}

Example

git checkout upstream/develop -- public/js/index.js
like image 69
Venkat.R Avatar answered Oct 17 '22 07:10

Venkat.R


Can also be done using git restore

git restore --source origin/master filename

like image 21
Lorentz Lasson Avatar answered Oct 17 '22 07:10

Lorentz Lasson