Git shallow fetch of a new tag

别来无恙 提交于 2019-12-07 01:09:10

问题


If I clone a repository with max depth of 1 at a tag, it works and pulls down just that. If I then want to do a fetch with or without depth of 1 for a new tag, it does some processing, but the tag never shows up under 'git tag'. If I supply the --tags option, it downloads the whole repository rather than just the new information. I don't mind the repository getting more history, I just want to avoid the download times. Is there any way to get a new tag without getting all tags from a shallow cloned repository?

git clone --branch 1.0 --depth 1 repositoryPath
git fetch --depth 1 origin tags/1.1 # Does processing but no new tags
git fetch --tags origin tags/1.1 # Pulls down the rest of the repository and adds all tags
git fetch --depth 1 --tags origin tags/1.1 # Same as above

Now, I have noticed this in the documentation: "--depth ... Tags for the deepened commits are not fetched."

Is this what I'm running into? Is there no way to do this besides downloading all tags?


回答1:


You can use the full <refspec> format:

git fetch --depth 1 origin refs/tags/1.1:refs/tags/1.1

Or, as specified in git-fetch options (under <refspec>):

tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>; it requests fetching everything up to the given tag.

So the short form answer to your question would be

git fetch --depth 1 origin tag 1.1


来源:https://stackoverflow.com/questions/26617862/git-shallow-fetch-of-a-new-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!