Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

git - 是否进行“ git导出”(如“ svn导出”)?(Do a “git export” (like “svn export”)?)

I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the .git repository directory.

(我一直在想是否有一个好的“ git export”解决方案来创建没有.git存储库目录的树的副本。)

There are at least three methods I know of:

(我至少知道三种方法:)

  1. git clone followed by removing the .git repository directory.

    (git clone然后删除.git存储库目录。)

  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.

    (git checkout-index暗示了此功能,但以“只需将所需的树读入索引...”开头,我不确定该怎么做。)

  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.

    (git-export是第三方脚本,其本质上是将git clone到临时位置,然后将rsync --exclude='.git' git clone到最终目标位置。)

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.

(最接近svn export选项可能是选项1,因为这两个选项均要求目标目录首先为空。)

But option 2 seems even better, assuming I can figure out what it means to read a tree into the index.

(但是,假设我能弄清楚将树读入索引的含义,选项2似乎更好。)

  ask by Greg Hewgill translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Probably the simplest way to achieve this is with git archive .

(可能最简单的方法是使用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中“导出”某些内容,无论如何我都想要压缩的存档,所以我要做类似的事情。)

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

ZIP archive:

(ZIP存档:)

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

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

(git help archive以获取更多详细信息,它非常灵活。)


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.

(请注意,即使存档中不包含.git目录,但该存档中也会包含其他特定于git的隐藏文件,例如.gitignore,.gitattributes等。如果您不希望它们出现在存档中,请确保请在.gitattributes文件中使用export-ignore属性,并在进行归档之前提交。)

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)

((有关更多详细信息,请参见格雷格的答案 ))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...