Git Clone:请只提供这些文件? [英] Git Clone: Just the files, please?

查看:223
本文介绍了Git Clone:请只提供这些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想克隆GIT仓库,而不是以 .git 目录结束。换句话说,我只是想要这些文件。有没有办法做到这一点?



git clone --no-checkout 与我想要的完全相反(只给出了目录)。



我试图为远程回购执行此操作,而不是一个本地的,这意味着这是不是重复 https://stackoverflow.com/questions/160608/how-to-do-a-git-export-like- svn-export>如何做一个git export(比如svn export)(尽管解决方案最终可能是相同的)。 h2_lin>解决方案

与您正在寻找的最接近的git命令将由 git archive

请参阅备份使用git的项目:它将在档案中包含所有文件(包括子模块,如果你是使用 git-archive-all 脚本)



然后,您可以在任何地方使用该归档文件,只返回文件,不包含 .git 目录。

  git archive --remote =< repository URL> | tar -t 

如果您需要第一级文件夹和文件:

  git archive --remote =< repository URL> | tar -t --exclude =* / *

仅列出一级文件夹远程回购:

  git archive --remote =< repository URL> | tar -t --exclude =* / *| grep/

注意:不适用于GitHub(不支持)



所以你需要克隆(浅显加快克隆步骤),然后在本地存档

  git clone --depth = 1 git@github.com:xxx / yyy.git 
cd yyy
git archive --format = tar aTag -o aTag.tar






另一个选择是做一个浅层克隆(如下所述)其他地方的.git文件夹。

  git --git-dir = / path / to / another / folder.git clone  - depth = 1 / url / to / repo 

repo文件夹只包含文件,不包含 .git



注意: git --git-dir 命令 git 的选项,不是 git clone




使用Git 2.14.X / 2.15(2017年第4季度)进行更新:它会确保避免添加空文件夹


git archive ,特别是与pathspec一起使用时,在其输出中存储一个空的
目录, Git本身从来不这样做。

这已被修正。 commit 4318094 (2017年9月12日)作者:RenéScharfe(``)

推荐方式: Jeff King( peff

(由 Junio C Hamano - gitster -


存档:不要将空目录添加到归档文件中



虽然git没有跟踪空目录,但是 git archive 可能会被诱骗放入档案中。

虽然对象数据库支持它,但它不能在索引中表示,因此不太可能在野外发生。



由于空目录不被git支持,它们也不应该被写入到存档中。
如果真的需要一个空目录,那么它可以通过在其中放置一个空的 .gitignore 文件来跟踪和存档。



I want to clone a GIT repo and NOT end up with a .git directory. In other words I just want the files. Is there a way to do this?

git clone --no-checkout did the exact opposite of what I want (gave me just the .git directory).

I am trying to do that for a remote repo, not a local one, meaning this is not a duplicate of "How to do a "git export" (like "svn export")" (even though the solution might end up being the same).

解决方案

The git command that would be the closest from what you are looking for would by git archive.
See backing up project which uses git: it will include in an archive all files (including submodules if you are using the git-archive-all script)

You can then use that archive anywhere, giving you back only files, no .git directory.

git archive --remote=<repository URL> | tar -t

If you need folders and files just from the first level:

git archive --remote=<repository URL> | tar -t --exclude="*/*"

To list only first-level folders of a remote repo:

git archive --remote=<repository URL> | tar -t --exclude="*/*" | grep "/"

Note: that does not work for GitHub (not supported)

So you would need to clone (shallow to quicken the clone step), and then archive locally:

git clone --depth=1 git@github.com:xxx/yyy.git
cd yyy
git archive --format=tar aTag -o aTag.tar


Another option would be to do a shallow clone (as mentioned below), but locating the .git folder elsewhere.

git --git-dir=/path/to/another/folder.git clone --depth=1 /url/to/repo

The repo folder would include only the file, without .git.

Note: git --git-dir is an option of the command git, not git clone.


Update with Git 2.14.X/2.15 (Q4 2017): it will make sure to avoid adding empty folders.

"git archive", especially when used with pathspec, stored an empty directory in its output, even though Git itself never does so.
This has been fixed.

See commit 4318094 (12 Sep 2017) by René Scharfe (``).
Suggested-by: Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 62b1cb7, 25 Sep 2017)

archive: don't add empty directories to archives

While git doesn't track empty directories, git archive can be tricked into putting some into archives.
While that is supported by the object database, it can't be represented in the index and thus it's unlikely to occur in the wild.

As empty directories are not supported by git, they should also not be written into archives.
If an empty directory is really needed then it can be tracked and archived by placing an empty .gitignore file in it.

这篇关于Git Clone:请只提供这些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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