简体   繁体   中英

git - how to get a specific file from a remote repository

In my remote repo, I have multiple versions of a file that were all added and committed to the repository.

git log confirms that I have 4 versions. What i don't know how to do is to get a specific version from the remote repo down to my local directory.

Both my local directory and remote repo, for now, reside on my computer. This is because it is a new installation and we are trying to figure out how GIT works.

If you do a git pull origin master , you should have all the commits/versions in the local repo as the master branch of the remote repo.

If you do not want all the changes, you can get a specific commit from the remote repo by doing git fetch origin SHA1-commit:refs/remotes/origin/foo-commit

If you only want a specific file, you could do -

git fetch
git checkout origin/master -- path/to/file

This would download all the changes from the remote repo, but would only apply the changes for the specific path.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM