执行“git export” (如“svn export”)? [英] Do a "git export" (like "svn export")?

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

问题描述

我一直在想,是否有一个很好的git导出解决方案,创建一个没有 .git 存储库目录的树的副本。我知道至少有三种方法:


  1. git clone .git 存储库目录。

  2. git checkout-index 暗示了此功能,但以Just read所需的树进入索引...我不完全确定该怎么做。

  3. git-export 是基本上执行 git clone 到一个临时位置,后跟 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 help






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

  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:

  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 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屋!

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