git - only fetch the files, not the history

十年热恋 提交于 2019-12-22 10:47:02

问题


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?


回答1:


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>

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.

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




回答2:


You can use a shallow clone:

git clone --depth=1 git://url/of/repo

However you won't be able to commit/push changes made in a shallow clone.




回答3:


If there is a webview like gitweb or cgit, you can very well take a snapshot. But I don't think fetch of the code alone is possible. Because fetch is working on your git objects and not the code.

git archive --format=tar --remote=gitolite@server:repo.git HEAD | bzip2 > repo-snapshot.tar.bz2


来源:https://stackoverflow.com/questions/16011184/git-only-fetch-the-files-not-the-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!