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
Git archive is a helpful utility for creating distributable packages of git repositories. Git archive can target specific refs of a repository and only package the contents of that ref. Git archive has several output formats that can utilize added compression.
The available list of formats can be retrieved with the git archive --list command. But the Git archive command includes only the files, not the history of those files.
The folder is created when the project is initialized (using git init ) or cloned (using git clone ). It is located at the root of the Git project repository. If we delete the . git folder, the information saved by Git will be lost, and the directory will no longer act as a Git repository.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With