从 github 远程仓库 git 导出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9609835/
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
git export from github remote repository
提问by Adrian Gunawan
I'd like to export from github remote repository, not cloning it. Similar to svn export, I do not want to get .git folder with it. I can work around it by cloning and removing .git folder. I wonder if there is a cleaner way?
我想从 github 远程存储库导出,而不是克隆它。与 svn export 类似,我不想用它获取 .git 文件夹。我可以通过克隆和删除 .git 文件夹来解决它。我想知道是否有更清洁的方法?
I read it somewhere you can use git archive to achieve this.
我在某个地方读过它,您可以使用 git archive 来实现这一点。
However I got the following errors..
但是我得到了以下错误..
$ git archive --format=tar [email protected]:xxx/yyy.git master | tar -xf -
Invalid command: 'git-upload-archive 'xxx/yyy.git''
You appear to be using ssh to clone a git:// URL.
Make sure your core.gitProxy config option and the
GIT_PROXY_COMMAND environment variable are NOT set.
fatal: The remote end hung up unexpectedly
Any help would be great. Thanks.
任何帮助都会很棒。谢谢。
回答by janos
Thanks to the Subversion support by GitHub, you can use svn export
to get the project without any version control files:
感谢 GitHub 对 Subversion 的支持,您可以使用它svn export
来获取没有任何版本控制文件的项目:
svn export https://github.com/user/project/trunk
Notice the URL format:
注意 URL 格式:
- The base URL is
https://github.com/
USERNAME/PROJECTNAME
without.git
/trunk
appended at the end
- 基本网址是
https://github.com/
USERNAME/PROJECTNAME
没有.git
/trunk
附加在最后
This way you can get branches and subdirectories too.
这样你也可以得到分支和子目录。
This creates a directory with the exported files. It's not possible to create a tar/zip directly, you have to do in two steps (export + zip). This is a limitation of svn export
itself.
这将创建一个包含导出文件的目录。无法直接创建 tar/zip,您必须分两步进行(导出 + zip)。这是对svn export
自身的限制。
As @Jonpointed out, this will create the export in a directory named trunk
by default. You can specify a different name if you prefer:
正如@Jon指出的那样,这将在trunk
默认命名的目录中创建导出。如果您愿意,可以指定不同的名称:
svn export https://github.com/username/projectname/trunk projectname
You can use this technique to export any sub-directory of the project.
For example if you want only some/path
, you can do:
您可以使用此技术导出项目的任何子目录。例如,如果你只想要some/path
,你可以这样做:
svn export https://github.com/username/projectname/trunk/some/path local-dir-name
You can get paths from branches and tags too. The endpoint https://github.com/username/projectname
behaves fully as a Subversion repository with a regular layout, so you will find branches in https://github.com/username/projectname/branches
and tags in https://github.com/username/projectname/tags
.
您也可以从分支和标签获取路径。端点https://github.com/username/projectname
完全表现为具有常规布局的 Subversion 存储库,因此您将https://github.com/username/projectname/branches
在https://github.com/username/projectname/tags
.
Before you export something large by mistake, it's good to check first the content of the path. You can do that using svn ls
, for example:
在错误地导出大文件之前,最好先检查路径的内容。您可以使用svn ls
,例如:
svn ls https://github.com/username/projectname/
Normally this should give you:
通常这应该给你:
branches/
tags/
trunk/
You could iteratively explore the repository this way.
您可以通过这种方式迭代地探索存储库。
回答by rathers
If you're only interested in exporting from GitHub then they provide a mechanism to download tarballs. For example:
如果您只对从 GitHub 导出感兴趣,那么他们提供了一种下载 tarball 的机制。例如:
https://github.com/torvalds/linux/downloads
https://github.com/torvalds/linux/downloads
Even though it says "there aren't any downloads for this repository." you can still use the buttons to download a tarball of the master branch.
即使它说“此存储库没有任何下载”。您仍然可以使用按钮下载 master 分支的 tarball。
Or see this link for a list of tarballs linked to tags:
或查看此链接以获取链接到标签的 tarball 列表:
https://github.com/torvalds/linux/tags
https://github.com/torvalds/linux/tags
This should work for any GitHub repo, not just the linux kernel.
这应该适用于任何 GitHub 存储库,而不仅仅是 linux 内核。
回答by LAFK says Reinstate Monica
For unknown (to me at least) reasons GitHub doesn't support this.
由于未知(至少对我而言)原因,GitHub不支持此.
We don't support people running git-archive against our servers.
Seems silly, since via SVN you can, but... I upvoted @Janos' answer.
看起来很傻,因为通过 SVN 你可以,但是......我赞成@Janos 的回答。
回答by Samuel Tardieu
If your goal is to limit the quantity of information exchanged with the server, have you considered using clone
with --depth
? You would still need to remove the (much reduced) .git
subdirectory though:
如果您的目标是限制与服务器交换的信息量,您是否考虑过使用clone
with --depth
?您仍然需要删除(大大减少).git
子目录:
git clone --depth=1 [email protected]:xxx/yyy.git && rm -rf yyy/.git
回答by Jarl
If you need this for named commits (that is branches and tags), then you can use git clone --depth=1
combined with git archive
如果你需要这个命名提交(即分支和标签),那么你可以git clone --depth=1
结合使用git archive
It is worth knowing that git clone --depth=1
clones all top commits on all branches and tags(not only master
). So after doing such a shallow clone you can enter the local directory and make a git archive --format=tar tag_to_be_exported
.
值得知道的是,git clone --depth=1
克隆了所有分支和标签上的所有顶级提交(不仅是master
)。所以在做了这么浅的克隆之后,你可以进入本地目录并制作一个git archive --format=tar tag_to_be_exported
.
So if you want to export the tag release1.1
所以如果你想导出标签 release1.1
git clone --depth=1 [email protected]:xxx/yyy.git
cd yyy
git archive --format=tar release1.1 -o release1.1.tar
So unnless you need to export unnamed commit-ids, this may be a good solution.
因此,除非您需要导出未命名的提交 ID,否则这可能是一个很好的解决方案。
回答by Gihan De Silva
I think it is not possible to export github repository with git archive. Please read this
我认为用 git archive 导出 github 存储库是不可能的。请阅读这个
https://help.github.com/articles/can-i-archive-a-repository
https://help.github.com/articles/can-i-archive-a-repository
Only possible ways are
唯一可能的方法是
git clone
github download (ZIP) button
回答by 3cheesewheel
I ran into this same problem before, and AFAICT, it only seems to work with Bitbucket, e.g.
我之前遇到过同样的问题,而且 AFAICT,它似乎只适用于 Bitbucket,例如
ysim:~/repos$ git archive --format=tar --prefix=alembic/ --remote=ssh://[email protected]/zzzeek/alembic.git master | tar -xf -
ysim:~/repos$ ls
alembic
But I found a workaround for GitHub using wget - so in the new GitHub interface, you'll find a button that says "Download ZIP" on the bottom of the right sidebar; right-click on it and copy the link address.
但是我找到了一个使用 wget 的 GitHub 解决方法——所以在新的 GitHub 界面中,你会在右侧边栏的底部找到一个写着“下载 ZIP”的按钮;右键单击它并复制链接地址。
Next, in the command line (I got the idea from here):
接下来,在命令行中(我从这里得到了这个想法):
wget -qO- -O tmp.zip <zipball url> && unzip tmp.zip && rm tmp.zip
That will unzip it to a directory called something like repo-master/
.
这会将它解压缩到一个名为repo-master/
.
If you want, you can also alias this in your .gitconfig
so you don't have to remember/type all of that out, e.g.
如果你愿意,你也可以在你的别名中.gitconfig
这样你就不必记住/输入所有这些,例如
export = "! f() { wget -qO- -O tmp.zip \"\" && unzip tmp.zip && rm tmp.zip; }; f"
So you can just do something like this in the shell:
所以你可以在 shell 中做这样的事情:
ysim:~/repos$ git export https://github.com/ysim/verbinski/archive/master.zip
ysim:~/repos$ ls
verbinski-master
回答by Anto
One way to achieve this is to use the SVN support offered by GIT.
实现此目的的一种方法是使用 GIT 提供的 SVN 支持。
Steps to perform as root one off are (for Cent os);
以 root 身份执行的步骤是(对于 Cent 操作系统);
yum install git
yum install subversion
Then to do a selective export the following syntax should be used:
然后要进行选择性导出,应使用以下语法:
svn export <git repository>/<source folder> <empty target folder> --no-auth-cache --force --username <active directory username>
If you do not use parameter --no-auth-cache when prompted to save the password type "no" for security reasons, or it will be saved unencrypted.
如果出于安全原因,在提示保存密码时不使用参数 --no-auth-cache,请键入“no”,否则保存时将不加密。
When translating from the GIT notation to the SVN notation the following mapping applies; replace "tree/master" with "trunk" for master replace "tree/branch_name" with "branches/branch_name" for branches
当从 GIT 表示法转换为 SVN 表示法时,以下映射适用;将“树/主”替换为“主干”作为主将“树/分支名称”替换为“分支/分支名称”作为分支
This works for both files and directories.
这适用于文件和目录。
回答by Ariel Gabizon
If you need to get a tarball of a commit on github I think this is the easiest way:
如果您需要在 github 上获取提交的 tarball,我认为这是最简单的方法:
Say your repository name is
https://github.com/arielgabizon/librustzcash
假设您的存储库名称是
https://github.com/arielgabizon/librustzcash
and the commit id is
4be41ca6160c16abfd983c8c878b6ea04105b224
并且提交 ID 是
4be41ca6160c16abfd983c8c878b6ea04105b224
Just go in your browser to the address
https://github.com/arielgabizon/librustzcash/archive/4be41ca6160c16abfd983c8c878b6ea04105b224.tar.gz
只需在浏览器中访问该地址
https://github.com/arielgabizon/librustzcash/archive/4be41ca6160c16abfd983c8c878b6ea04105b224.tar.gz
and, at least on google chrome, it will start downloading the file.
并且,至少在谷歌浏览器上,它将开始下载文件。
回答by Marvin Pinto
For a normalexport:
对于正常导出:
$ git archive master | tar -x -C /path/to/destination
For a ziparchive:
对于zip存档:
$ git archive --format zip --output /path/to/destination/file.zip master
Of course for this to work, you'll need to clone it locally first, there's no cleanway around that.
当然,要使其正常工作,您需要先在本地克隆它,没有干净的方法可以解决。