git:拉取特定分支,只保留最新的树(没有任何历史)

git: pull specific branch, keep only the latest tree (without any history)

如何从远程存储库中提取特定分支,只检查最新的树而不保留任何历史记录?

这个问题与检查 Gentoo 的 Portage 树特别相关:我想更新我的 Portage 树,不保留任何历史记录,最小化 /usr/portage/.git 的大小。

像这样:

$ git clone --branch dotnet-mono-eclass-lat --depth 1 https://anongit.gentoo.org/git/repo/gentoo.git

来自man git-clone

--branch <name>, -b <name>

Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out.

--depth <depth>

Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.

下载没有历史记录的存储库: git 克隆 --depth 1

要更新已克隆的浅存储库:

git pull --depth 1 or git pull --update-shallow