问题
I would like to add a tag to a file to easily download that file and not the entire branch.
How do I download a specific file in GIT?
回答1:
I am not aware of any way to tag specific files in git
.
For the second question: How do I download a specific file in git
?
The following works only if you mean "download while in a git
repository" (That's how I understand your question, if you mean with git without having the repository see Get a single file from a remote git repository
or Not able to extract single file from remote git server
)
$ git checkout tagged-commit -- path/to/file.example
Where tagged-commit
can be a lot of things, among others:
- A commit hash
- A git tag
- A branch name
- For more ways see gitrevisions
回答2:
The way git
works is by adding a tag to the entire tree at the state of the commit. There is no way to add a tag to a single file.
Since you are using gitlab, you can just download the file in the right revision from the web interface.
回答3:
For GitLab specifically, downloading a single file is now explicitly supported, since GitLab 11.2 (August 22nd, 2018), thank to Kia Mei Somabes .
See "Download individual repository files":
When browsing through a project repository on GitLab, the need to download a specific file frequently arises. Until now, this was only possible within the GitLab interface by viewing the file in a new browser tab and then saving it.
GitLab 11.2 introduces a new “
Download
” button in the file viewer interface, available for each individual repository file, allowing you to download any file directly from the application more easily.
- See documentation,
- see issue,
- see merge-request.
来源:https://stackoverflow.com/questions/48301185/how-to-tag-a-single-file-or-how-do-i-download-a-specific-file-git