Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-archive a subdirectory --

I'm using git-archive to archive a subdirectory in a git repo, like so:

git archive -o ../subarchive.zip HEAD subdir/* 

However the resulting archive maintains the subdir/ directory structure, i.e. the contents are:

subdir/    whatever.js    morestuff.js 

When I actually want whatever.js and morestuff.js at the root of the archive.

How do? Thanks.

like image 732
wildabeast Avatar asked Jun 27 '13 18:06

wildabeast


People also ask

How do I archive in git?

To archive a repository, go to your Repository Settings Page and click Archive this repository. Before archiving your repository, make sure you've changed its settings and consider closing all open issues and pull requests.

Can I clone a subdirectory in git?

Cloning only a subdirectory is not possible in Git. The network protocol doesn't support it, the storage format doesn't support it. Every single answer to this question always clones the whole repository.

Can you archive a branch in git?

There will be a archive option for each branch, beside the delete option for the branch. A user selecting that will get prompted to be sure they want to archive the branch. Archiving the branch will result in the branch only showing on a new Archived tab on the branches page.

What is a subdirectory in git?

git. Git uses this special subdirectory to store all the information about the project, including all files and sub-directories located within the project's directory. If we ever delete the . git subdirectory, we will lose the project's history. Next, we will change the default branch to be called main .

How to pull a directory from a sub-repository in Git?

Git can pull a directory contained in a sub-repository simply enabling “sparseCheckout” config in the root Repository. Every directory is needed in local repo must be indicated “spare-checkout” file under .git/info directory Next issue a simple git pull.

How do I archive a project in Git?

You can use any commit or tag ID instead of HEAD to archive the project at a certain point. If you want to add a prefix (e.g., a top level folder) to every file: You can also adjust the compression level between 0 (no compression) and 9 (maximum compression) inclusive, for example For other options, see the help page ( git help archive ).

Why doesn’t my Git archive work with my second format?

But that’s not how git archive works! It needs a local repository–which you have suppressed by using GIT_STRATEGY: none. Your second format accesses an archive in the remote repository, it doesn’t create an archive from the repository.

What does <prefix> mean in Git archive?

If <prefix> is specified it is prepended to the filenames in the archive. git archive behaves differently when given a tree ID versus when given a commit ID or tag ID.


1 Answers

You can do that like this:

git archive -o ../subarchive.zip HEAD:subdir 

By the way, an easy way to play with the command and see what it will generate is if you use it in this form:

git archive --format=tar HEAD:subdir | tar t git archive --format=tar HEAD subdir | tar t # ... and so on ... 

Once you see what you're looking for, you can change the format and use the -o flag to actually create the archive.

like image 104
janos Avatar answered Oct 05 '22 21:10

janos