Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I git archive an arbitrary branch?

Tags:

git

git checkout master
git archive stage | tar -czf archive.tar.gz htdocs
# archives master because it's checked out.

How can I archives the stage branch, regardless of the current I'm on?

like image 557
Ryan Florence Avatar asked May 26 '10 16:05

Ryan Florence


People also ask

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.

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.

How do I terminate a branch?

If you want to delete a branch completely, you can just delete it in all your repositories (typically local and remote). git will then clean it up next time it garbage collects.

How do I export a file from git?

There is no "git export" command, so instead you use the "git archive" command. By default, "git archive" produces its output in a tar format, so all you have to do is pipe that output into gzip or bzip2 or other.


1 Answers

git archive creates a tar archive so you don't need to pipe its output tar, indeed it's not doing what you expect. You are creating an tar archive of the stage branch and piping it to a normal tar command which doesn't use its standard input but just creates its own archive of htdocs in the working tree, independently of git.

Try:

git archive stage >stage.tar

or, for a compressed archive:

git archive stage | gzip >stage.tar.gz

To just archive the htdocs subfolder you can do:

git archive stage:htdocs | gzip >stage-htdocs.tar.gz

or, to include the folder name in the archive:

git archive --prefix=htdocs/ stage:htdocs | gzip >stage-htdocs.tar.gz

or more simply:

git archive stage htdocs | gzip >stage-htdocs.tar.gz
like image 108
CB Bailey Avatar answered Sep 28 '22 03:09

CB Bailey