执行“git export” (如“svn export”)? [英] Do a "git export" (like "svn export")?
问题描述
.git
存储库目录的树的副本。我知道至少有三种方法:-
git clone
.git
存储库目录。 -
git checkout-index
暗示了此功能,但以Just read所需的树进入索引...我不完全确定该怎么做。 -
git-export
是基本上执行git clone $的第三方脚本c $ c>到一个临时位置,后跟
rsync --exclude ='。git'
到最终目的地。
这些解决方案都没有真的让我感到满意。最接近 svn export
可能是选项1,因为两者都要求目标目录为空。但是,选项2似乎更好,假设我可以弄清楚将树读入索引是什么意思。
可能是最简单的方法是使用 git archive
。如果你真的需要扩展的树,你可以做这样的事情。
git archive master | tar -x -C /某处/ else
大部分时间我需要导出从git,我想要压缩的档案在任何情况下,所以我做这样的事情。
git archive master | bzip2> source-tree.tar.bz2
ZIP档案:
git archive --format zip --output /full/path/to/zipfile.zip master
注意:如果您有兴趣导出索引,命令是
git checkout-index -a -f --prefix = / destination / path /
(请参阅 Greg's answer 了解更多详情)
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:
git clone
followed by removing the.git
repository directory.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.git-export
is a third party script that essentially does agit clone
into a temporary location followed byrsync --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 those 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.
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 export”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!