[英]Change remote branch of repository and pull only the changes
I have a remote repository that has a lot of branches. 我有一个具有很多分支的远程存储库。 Every time there is a new version, a new branch is created.
每次有新版本时,都会创建一个新分支。 How can I, when a new version is available, change the branch and pull the changes avoiding to clone it all again.
当有新版本可用时,如何更改分支并撤消更改,以避免再次克隆所有分支。 I want to only download the new committs.
我只想下载新的提交。
git fetch origin
git checkout new-version`
Where origin
is the remote name and new-version
is the branch name. 其中
origin
是远程名称,而new-version
是分支名称。
The documentation for git fetch
says: git fetch
的文档说:
Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories.
从一个或多个其他存储库中获取分支和/或标签(统称为“ refs”),以及完成其历史记录所需的对象。 Remote-tracking branches are updated.
远程跟踪分支已更新。
This basically means that it goes and downloads the history of the repository from the remote. 这基本上意味着它可以从远程下载存储库的历史记录。 However, a repository can have multiple remotes, so
git fetch
can fetch either one or more of them using the --all
flag. 但是,一个存储库可以有多个远程站点,因此
git fetch
可以使用--all
标志获取一个或多个远程--all
。
By default, any tag that points into the histories being fetched is also fetched;
默认情况下,任何指向要获取的历史记录的标记也将被获取; the effect is to fetch tags that point at branches that you are interested in. This default behavior can be changed by using the --tags or --no-tags options... By using a refspec that fetches tags explicitly, you can fetch tags that do not point into branches you are interested in as well.
效果是获取指向您感兴趣的分支的标签。可以使用--tags或--no-tags选项来更改此默认行为...通过使用显式获取标签的refspec,您可以获取也不会指向您感兴趣的分支的标记。
Meaning that if you had, for example, branches A, B & C on the remote, and on local you were working on branch C . 这意味着,例如,如果在远程和本地具有分支机构A,B和C ,则您正在分支C上工作。 If you
git fetch origin C
, by default, this will also fetch the tags pointing to that branch, but it will not fetch those related to other branches, for instance A and B . 如果您
git fetch origin C
,默认情况下,这还将获取指向该分支的标签,但不会获取与其他分支(例如A和B)相关的标签。
If you want to fetch all tags, you just add the --tags
to the command. 如果要获取所有标签,只需将
--tags
添加到命令中。
Finally, 最后,
When no remote is specified, by default the origin remote will be used, unless there's an upstream branch configured for the current branch.
如果未指定任何远程,默认情况下将使用源远程,除非为当前分支配置了上游分支。
git fetch
documentation , it's all well explained. git fetch
documentation ,这一切都很好解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.