使用 git 获取最新版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1209999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:48:37  来源:igfitidea点击:

Using git to get just the latest revision

git

提问by yuit

I want to track a project that uses git. I don't want to clone the full repository and the full history, I just want the latest revision, and I want to be able to update to new revisions from the remote project.

我想跟踪一个使用 git 的项目。我不想克隆完整的存储库和完整的历史记录,我只想要最新的修订版,并且我希望能够从远程项目更新到新的修订版。

I have tried using git clone, but this creates a copy of the entire repository (huge file size), and tracking changes makes the disk space even bigger (100mb of files now takes up over 2gb).

我曾尝试使用 git clone,但这会创建整个存储库的副本(巨大的文件大小),并且跟踪更改会使磁盘空间更大(100mb 的文件现在占用超过 2gb)。

I'm not going to be submitting patches, and I don't need the history. I just want the latest version like in subversion.

我不会提交补丁,我也不需要历史记录。我只想要像 subversion 一样的最新版本。

Is this possible in git?

这在git中可能吗?

回答by Greg Hewgill

Use the --depthoption in git clone:

使用中的--depth选项git clone

Create a shallowclone with a history truncated to the specified number of commits.

创建一个克隆,其历史记录被截断为指定的提交次数。

example: git clone --depth=1 <remote_repo_url>

例子: git clone --depth=1 <remote_repo_url>

回答by Jakub Nar?bski

Alternate solution to doing shallow clone (git clone --depth=1 <URL>) would be, if remote side supports it, to use --remoteoption of git archive:

执行浅克隆 ( git clone --depth=1 <URL>) 的替代解决方案是,如果远程端支持它,则使用git archive--remote选项:

$ git archive --format=tar --remote=<repository URL> HEAD | tar xf -

Or, if remote repository in question is browse-able using some web interfacelike gitweb or GitHub, then there is a chance that it has 'snapshot' feature, and you can download latest version (without versioning information) from web interface.

或者,如果有问题的远程存储库可以使用某些Web 界面(如 gitweb 或 GitHub)进行浏览,那么它可能具有“快照”功能,您可以从 Web 界面下载最新版本(没有版本信息)。