2015-02-06 112 views
3

git存档可以包含.git项目所在的目录吗?git存档可以包含.git项目所在的目录吗?

例如,假设我的目录结构是这样的:

-- /my-project-dir 
----- /.git 
----- /css 
----- index.html 
----- scripts.js 

默认情况下,当我做了git的存档,我结束了一个ZIP文件,像这样:

-- my-project-dir.zip 
----- /css 
----- index.html 
----- scripts.js 

我想知道是否有一种方法,archive命令也可以包含父目录,例如:

-- my-project-dir.zip 
----- /my-project-dir 
-------- /css 
-------- index.html 
-------- scripts.js 
+0

我使用'git bundle'这只是一个你可以克隆的文件。 – exussum 2015-02-06 15:37:11

回答

5

使用--prefix选项:

$ pwd 
/tmp/foo 
$ ls -A 
bar .git 
$ git archive --prefix foo/ -o foo.tar master 
$ tar tf foo.tar 
foo/ 
foo/bar 

小心包括在foo/最后的斜线,否则你最终前置到每个文件名前缀!