git-仅获取文件,不获取历史记录 [英] git - only fetch the files, not the history

查看:135
本文介绍了git-仅获取文件,不获取历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行git pullgit fetch时,我显然会同时检索历史记录和文件.对于大型项目,这会花费很多时间.我不知道如何加快这个过程,因为对于某些项目,我只对源代码感兴趣,而对历史不感兴趣.有没有办法告诉git我只想获取文件的当前快照,而不是整个历史记录?

when I am running git pull or git fetch, I obviously retrieve both history and files. For huge projects, that takes very much time. I wonder how this process could be sped up, as for some projects I am only interested in the source code and not in the history. Is there a way to tell git that I only want to fetch the current snapshot of the files and not the whole history as well?

推荐答案

您可能想看看git clone中的--depth选项-称为浅克隆".特别是,您可能想要:

You probably want to look at the --depth option in git clone--called a "shallow clone". In particular, you probably want:

git clone --depth=1 <url>

如果该项目位于GitHub上,则始终可以从那里使用下载链接.请注意,使用浅表克隆有一些问题:

If the project is on GitHub, you can always use the download links from there. Note, there are some catches to using a shallow clone:

创建一个浅表克隆,其历史记录将被截断为指定的修订版本数.浅层存储库有很多限制(您不能从中克隆或获取,也不能从中推入或推入其中),但是如果您仅对具有悠久历史的大型项目的最新历史感兴趣,并且想要将修补程序作为补丁发送.

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.

但这听起来像是您可以忍受的东西.

But that sounds like something you can live with.

此外,正电子指出,您也可以使用git archive来做到这一点.

Also, as positron pointed out, you can do this with git archive as well.

这篇关于git-仅获取文件,不获取历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆