让Git不跟踪所有分支

时间:2016-04-18 07:09:54

标签: git git-fetch

我有4个远程分支:A,B,C,D。A和B不再与我相关,但我想远程保留它们。因此,当我执行git fetch时,我只想获取C和D.

1 个答案:

答案 0 :(得分:3)

如何结帐特定分支

# fetch a remote branch from remote but the catch here is that the branch
# will not have a tracking branch. It will be checked out locally. 
git fetch <remote> <remote branch>:refs/remotes/<remotename>/<local branch>

几点注释:Git并不关心你的提交地点。

Git有一个大内容文件(.pack),用于存储存储库的所有内容。当你执行fetch时,它只是从远程执行所有内容。 Git没有“看到”该文件中的任何分支。

当你结帐分支git checkout这个分支的最新提交时。您当然可以移动和更改HEAD并将其设置为任何其他提交。

重点是git不关心标签,分支等。它只是跟踪内容,因为sommit存储其父git知道如何从该文件中提取“先前”提交。

<强> Summary

Git不跟踪分支或标签。它只是在内部存储SHA-1,并知道如何在需要时提取它们。

相关问题