threads / discuss / 20525

[Feature Request] git export

Subject: [Feature Request] git export

## tl;dr

7 messages between Aug 10, 2009 and Aug 11, 2009.

replies: 6people: 5as markdown or json

Thomas Koch· Aug 10, 2009, 16:22 UTC · lore

could you please provide a simple solution to save a tree object into an arbitrary location? I found some hints, that it would be possible by missusing either git checkout-index or git-archive, but I think that it shouldn't require that much GIT FU to do such a simple thing.

Thanks,
Thomas Koch, http://www.koch.ro
Tim Visher· Aug 10, 2009, 16:27 UTC · re: Thomas Koch · lore

Re: [Feature Request] git export

Hey Thomas,
On Mon, Aug 10, 2009 at 12:22 PM, Thomas Koch<thomas@koch.ro> wrote:
> could you please provide a simple solution to save a tree object into an
> arbitrary location?

This has been requested a few times and I have no idea what the development status of it is. Most people seem to recommend just making an alias around git checkout-index.

> I found some hints, that it would be possible by missusing either git
> checkout-index or git-archive, but I think that it shouldn't require that much
> GIT FU to do such a simple thing.

It's not really a misuse, as the [man page itself](http://www.kernel.org/pub/software/scm/git/docs/git-checkout-index.html) recommends using checkout-index as a way to export an entire tree. Until someone decides that it's worth making the porcelain command (like you perhaps) then I think you can just stick with checkout-index knowing you're not abusing anything.

-- 
In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail
Thomas Koch· Aug 10, 2009, 16:41 UTC · re: Tim Visher · lore

Re: [Feature Request] git export

Hi Tim,

thanks for your explanation. Still I don't get how to do it with git checkout- index. The man page says "Just read the desired tree into the index", but I don't know what is meant by this.

Show 20 quoted lines
> Hey Thomas,
>
> On Mon, Aug 10, 2009 at 12:22 PM, Thomas Koch<thomas@koch.ro> wrote:
> > could you please provide a simple solution to save a tree object into an
> > arbitrary location?
>
> This has been requested a few times and I have no idea what the
> development status of it is.  Most people seem to recommend just
> making an alias around git checkout-index.
>
> > I found some hints, that it would be possible by missusing either git
> > checkout-index or git-archive, but I think that it shouldn't require that
> > much GIT FU to do such a simple thing.
>
> It's not really a misuse, as the [man page
> itself](http://www.kernel.org/pub/software/scm/git/docs/git-checkout-index.
>html) recommends using checkout-index as a way to export an entire tree.
> Until someone decides that it's worth making the porcelain command (like
> you perhaps) then I think you can just stick with checkout-index knowing
> you're not abusing anything.
Thomas Koch, http://www.koch.ro
Tim Visher· Aug 10, 2009, 18:31 UTC · re: Thomas Koch · lore

Re: [Feature Request] git export

On Mon, Aug 10, 2009 at 12:41 PM, Thomas Koch<thomas@koch.ro> wrote:
> thanks for your explanation. Still I don't get how to do it with git checkout-
> index. The man page says "Just read the desired tree into the index", but I
> don't know what is meant by this.

No problem. That phrase gave me some trouble the first time I read it too. All it means is 'do a `git checkout` of the branch that you want to export'. `git checkout-index` will then do an export of the contents the branch that you currently have checked out.

Junio and Dscho's comments are possibly salient as well.
-- 
In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail
Junio C Hamano· Aug 10, 2009, 16:54 UTC · re: Thomas Koch · lore

Re: [Feature Request] git export

Thomas Koch <thomas@koch.ro> writes:
> could you please provide a simple solution to save a tree object into an 
> arbitrary location?
> I found some hints, that it would be possible by missusing either git 
> checkout-index or git-archive, but I think that it shouldn't require that much 

If you are talking about a tree object, then git-archive is what you want. It was invented almost for this exact purpose, but unlike "export" that would only copy to a directory, you can get a tarball out of it when you do not want to expand the result into a directory; it is more versatile form. The manual page for the command has an example (look for "/var/tmp") so I won't repeat the cut-and-paste recipe here.

If you are not talking about a tree object but is talking about the contents recorded in your index, checkout-index with the --prefix option may be what you want. The manual page for the command has an example (look for "--prefix=git-export-dir/") so I won't repeat it here.

Johannes Schindelin· Aug 10, 2009, 16:56 UTC · re: Thomas Koch · lore

Re: [Feature Request] git export

Hi,
On Mon, 10 Aug 2009, Thomas Koch wrote:
Show 6 quoted lines
> could you please provide a simple solution to save a tree object into an 
> arbitrary location?
>
> I found some hints, that it would be possible by missusing either git 
> checkout-index or git-archive, but I think that it shouldn't require 
> that much GIT FU to do such a simple thing.

You can check out Documentation/install-doc-quick.sh and find that something like

	GIT_INDEX_FILE=.git/tmp
	export GIT_INDEX_FILE
	git read-tree $TREE
	git checkout-index -a -f --prefix=/the/path
	unset GIT_INDEX_FILE
should work.

Hth, Dscho

Michael J Gruber· Aug 11, 2009, 07:50 UTC · re: Thomas Koch · lore

Re: [Feature Request] git export

Thomas Koch venit, vidit, dixit 10.08.2009 18:22:
Show 9 quoted lines
> could you please provide a simple solution to save a tree object into an 
> arbitrary location?
> I found some hints, that it would be possible by missusing either git 
> checkout-index or git-archive, but I think that it shouldn't require that much 
> GIT FU to do such a simple thing.
> 
> Thanks,
> 
> Thomas Koch, http://www.koch.ro
To serve you with an explicit command line, it's really only
git archive HEAD | tar -C wheretoexport/ -xf-

which you need to issue from within your git repo. Instead of HEAD, you can use any "treeish", for example the name of a branch, which need not be checked out. You can add path arguments after the treeish if you want to export only parts of your repo.

Note that in true unix philosophy, git archive does the (git specific) exporting only and leaves the importing into the file system (saving) to the proper tool. I mean, would you rather use cp -r or pipes with tar -x/tar -c or cpio -i/-o in order to copy a tree? ;)

Cheers, Michael

← back to recent threads