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?
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).
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.
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With