threads / discuss / 24649

Decompressing a tree to a location other than the working directory

Subject: Decompressing a tree to a location other than the working directory

## tl;dr

4 messages between Aug 6, 2010 and Aug 7, 2010.

replies: 3people: 4as markdown or json

Joshua Shrader· Aug 6, 2010, 18:43 UTC · lore

git checkout allows one to checkout a particular version of a certain path in the working directory. Are there accessible plumbing commands that can be used to accomplish the same thing, but change the target directory. For example, if I wanted to checkout a certain path, but wanted to check it out somewhere external to my working directory / repository?

Thanks,
Josh
Jonathan Nieder· Aug 6, 2010, 18:43 UTC · re: Joshua Shrader · lore

Re: Decompressing a tree to a location other than the working directory

Joshua Shrader wrote:
> git checkout allows one to checkout a particular version of a certain
> path in the working directory.  Are there accessible plumbing commands
> that can be used to accomplish the same thing, but change the target
> directory.

I don’t know if it is plumbing, but "git archive" is very useful for that.

 $ git archive HEAD^:Documentation | (cd elsewhere && tar xf -)

Hope that helps, Jonathan

Michael Witten· Aug 7, 2010, 03:10 UTC · re: Jonathan Nieder · lore

Re: Decompressing a tree to a location other than the working directory

On Fri, Aug 6, 2010 at 13:43, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 9 quoted lines
>> git checkout allows one to checkout a particular version of a certain
>> path in the working directory.  Are there accessible plumbing commands
>> that can be used to accomplish the same thing, but change the target
>> directory.
>
> I don’t know if it is plumbing, but "git archive" is very useful for
> that.
>
>  $ git archive HEAD^:Documentation | (cd elsewhere && tar xf -)
For single files (rather than directories), you could do this:
  git show HEAD^:path/to/file > /some/path/file
Jakub Narebski· Aug 6, 2010, 19:58 UTC · re: Joshua Shrader · lore

Re: Decompressing a tree to a location other than the working directory

Joshua Shrader <jshrader83@gmail.com> writes:
Show 6 quoted lines
> git checkout allows one to checkout a particular version of a certain
> path in the working directory.  Are there accessible plumbing commands
> that can be used to accomplish the same thing, but change the target
> directory.  For example, if I wanted to checkout a certain path, but
> wanted to check it out somewhere external to my working directory /
> repository?
Porcelain way: check out first example in git-archive(1) manpage
  EXAMPLES
  ========
  git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)
       Create a tar archive that contains the contents of the latest commit
       on the current branch, and extract it in the /var/tmp/junk directory.

Plumbing way: after preparing index (it can be separate file than .git/index), use "git checkout-index" as desceived in second example on manpage:

  EXAMPLES
  ========
  Using `git checkout-index` to "export an entire tree"
        The  prefix  ability  basically  makes  it trivial to use git check-
        out-index as an "export as tree" function.  Just  read  the  desired
        tree into the index, and do:
          $ git checkout-index --prefix=git-export-dir/ -a
        `git checkout-index` will "export" the index into the specified direc-
        tory.
        The final "/" is important. The exported name is literally just pre-
        fixed  with  the  specified string
-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads