Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull a specific file with GIT? [duplicate]

Tags:

Say you just want to get rid of the changes you've made to one file, and get back to whatever is in the repository. I used to do this in svn:

rm a-file.txt
svn update a-file.txt

What is the equivalent in Git? I know how to fetch/pull evrything from the repository, but how about one single file?

like image 467
Paul Casal Avatar asked Mar 25 '10 16:03

Paul Casal


People also ask

How do I pull only a specific file in git?

git checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).

Can I pull a single file from a git repository?

You can download an individual file from a GitHub repository from the web interface, by using a URL, or from the command line. You can only retrieve public files by URL or from the command line.

How do I pull one file from GitHub?

git checkout origin/master -- path/to/file // git checkout / -- path/to/file will checkout the particular file from the downloaded changes (origin/master). That's it!


1 Answers

To undo your (uncommitted) changes:

git checkout a-file.txt

If you have committed changes and want to undo them back to a certain previous commit:

git checkout [some-older-commit-ref] a-file.txt

Btw, with Subversion you should have done:

svn revert a-file.txt
like image 161
Martin Avatar answered Oct 20 '22 12:10

Martin