3

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?

3 Answers3

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.

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
2

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
AnimiVulpis
  • 2,670
  • 1
  • 19
  • 27
1

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.

https://about.gitlab.com/images/11_2/download-single-files.png

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250