做一个“git export"(如“svn 导出")? [英] Do a "git export" (like "svn export")?

查看:32
本文介绍了做一个“git export"(如“svn 导出")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道是否有好的git export"创建没有 .git 存储库目录的树副本的解决方案.我至少知道三种方法:

  1. git clone 然后删除 .git 存储库目录.
  2. git checkout-index 暗指这个功能,但开头是只需将所需的树读入索引...";我不完全确定该怎么做.
  3. git-export 是第三方脚本基本上将 git clone 复制到一个临时位置,然后将 rsync --exclude='.git' 复制到最终目的地.

这些解决方案都没有让我感到满意.最接近 svn export 的可能是选项 1,因为两者都要求目标目录首先为空.但选项 2 似乎更好,假设我能弄清楚将树读入索引意味着什么.

解决方案

可能最简单的方法是使用 git 存档.如果你真的只需要扩展树,你可以做这样的事情.

git 存档大师 |焦油 -x -C/某处/其他

大多数时候我需要从 git 中导出"一些东西,无论如何我都想要一个压缩的存档,所以我做这样的事情.

git 存档大师 |bzip2 >source-tree.tar.bz2

ZIP 存档:

git archive --format zip --output/full/path/to/zipfile.zip master

git help archive 了解更多详情,相当灵活.

<小时>

请注意,即使存档不包含 .git 目录,它也会包含其他隐藏的 git 特定文件,例如 .gitignore、.gitattributes 等.如果您不希望它们在存档中,确保在 .gitattributes 文件中使用 export-ignore 属性并在归档之前提交.阅读更多...<小时>

注意:如果你有兴趣导出索引,命令是

git checkout-index -a -f --prefix=/destination/path/

(有关详细信息,请参阅 Greg 的答案)

I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the .git repository directory. There are at least three methods I know of:

  1. git clone followed by removing the .git repository directory.
  2. git checkout-index alludes to this functionality but starts with "Just read the desired tree into the index..." which I'm not entirely sure how to do.
  3. git-export is a third-party script that essentially does a git clone into a temporary location followed by rsync --exclude='.git' into the final destination.

None of these solutions really strike me as being satisfactory. The closest one to svn export might be option 1, because both require the target directory to be empty first. But option 2 seems even better, assuming I can figure out what it means to read a tree into the index.

解决方案

Probably the simplest way to achieve this is with git archive. If you really need just the expanded tree you can do something like this.

git archive master | tar -x -C /somewhere/else

Most of the time that I need to 'export' something from git, I want a compressed archive in any case so I do something like this.

git archive master | bzip2 >source-tree.tar.bz2

ZIP archive:

git archive --format zip --output /full/path/to/zipfile.zip master 

git help archive for more details, it's quite flexible.


Be aware that even though the archive will not contain the .git directory, it will, however, contain other hidden git-specific files like .gitignore, .gitattributes, etc. If you don't want them in the archive, make sure you use the export-ignore attribute in a .gitattributes file and commit this before doing your archive. Read more...


Note: If you are interested in exporting the index, the command is

git checkout-index -a -f --prefix=/destination/path/

(See Greg's answer for more details)

这篇关于做一个“git export"(如“svn 导出")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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