GIT pull/fetch from specific tag

我们两清 提交于 2019-12-20 09:47:48

问题


Is there a way to pull/fetch code from a specific tag in a repo.

Am aware that after clone, i can checkout to the tag but is it possible to specify a tag during a pull?

In ClearCase i can rebase or deliver a specific baseline of code, is there a way where i can use git tags similarly to pull/push code upto a specified tag?


回答1:


It will be a bit different with ClearCase, because you can only rebase a baseline produced on the parent Stream (although you can deliver any baseline from any Stream to your Stream).
So there are some limitations to the kind of merge you do with ClearCase.

With Git, you can merge any commit to the HEAD of your current branch.
If that commit comes from a remote repo, it will be first imported in the remote branches of your local repo ('fetch' part of the git pull) and then merged.

 git pull [options] [<repository> [<refspec>…]]

The "refspec" part of the git pull command means you can pull anything.

<refspec> can name an arbitrary remote ref (for example, the name of a tag) or even a collection of refs with corresponding remote tracking branches (e.g., refs/heads/:refs/remotes/origin/), but usually it is the name of a branch in the remote repository.

See also How to pull remote branch with specified commit id?




回答2:


Pull is fetch + merge.

Talking about how to fetch a specific remote ref (either a tag or branch), probably an example is better at clarifying this:

git fetch origin :refs/remotes/origin/master

Or a shorter form:

git fetch origin :remotes/origin/master

Note this works even if remotes/origin/master has been removed locally.

Another example for creating a local branch directly from a remote tag

git fetch <repo_url> +refs/tags/<TAG>:<branch>


来源:https://stackoverflow.com/questions/3964368/git-pull-fetch-from-specific-tag

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