Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can git archive include the directory that the .git project lives in?

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
like image 613
Pete Avatar asked Feb 06 '15 15:02

Pete


People also ask

What does git archive do?

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.

Does git archive include history?

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.

What happens if the .git directory gets deleted?

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.


1 Answers

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!

like image 88
Thomas Avatar answered Sep 25 '22 06:09

Thomas