Can git archive include the directory that the .git project lives in?
For example, let's say my directory structure is like this:
-- /my-project-dir
----- /.git
----- /css
----- index.html
----- scripts.js
By default, when I do a git archive, I end up with a ZIP file like so:
-- my-project-dir.zip
----- /css
----- index.html
----- scripts.js
I'm wondering if there is a way that the archive
command can include the parent directory as well, for example:
-- my-project-dir.zip
----- /my-project-dir
-------- /css
-------- index.html
-------- scripts.js
Use the --prefix
option:
$ pwd
/tmp/foo
$ ls -A
bar .git
$ git archive --prefix foo/ -o foo.tar master
$ tar tf foo.tar
foo/
foo/bar
Be careful to include the trailing slash in foo/
, otherwise you end up with the prefix prepended to each filename!