git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Checking out on a different+partial directory

From
Jeff King <peff@peff.net>
Date
May 22, 2010, 05:48 UTC
Message-ID
<20100522054852.GB29118@coredump.intra.peff.net>
In-Reply-To
<19441.8259.634019.348195@winooski.ccs.neu.edu>
On Mon, May 17, 2010 at 06:53:55AM -0400, Eli Barzilay wrote:
Show 6 quoted lines
> Say that I have a repository at /some/dir, and a tree that contains
> most of its files at /another/dir (the second is a build directory,
> made with `git archive', so some files removed due to export-ignore
> attributes and some built files are present).
> 
> Is there a convenient way to make /some/dir usable as a repository?

Did you mean /another/dir? /some/dir is already a repository as per your description above (is it a bare repository or a regular one?).

Show 6 quoted lines
> Two things that I tried are
> 
>   git --work-tree=/another/dir reset --hard master
> 
> which one time, but then failed with "fatal: unable to read tree...",
> and another is

I would have thought that worked, assuming you were in /some/dir. And oddly, _some_ stuff works. I tried:

  mkdir repo && cd repo && git init
  echo content >file && git add . && git commit -m file
  git archive --format=tar --prefix=work/ HEAD | tar -C .. -xf -
to create the situation. Running
  cd repo
  git --work-tree=$PWD/../work diff-files
  git --work-tree=$PWD/../work diff

works as expected (the first one notices stat-dirtiness, and the second shows an empty diff). But then I get:

  $ git --work-tree=$PWD/../work reset --hard
  fatal: unable to read tree ea394696ee1f7f5b55ca0d97d37748933cf39095
So there is clearly a bug. I'll investigate.
Show 5 quoted lines
>   cp -a /some/dir/.git /another/dir
>   cd /another/dir
>   git reset --hard master
> 
> which looks like it can suffer from the same problem.
That should work, too.
> (It would be especially nice if there's a way to have only different
> files touched in /another/dir.)

Only different files will be rewritten, but git will have to read all of the files to determine their sha1 (usually it avoids this by checking stat info, but obviously your exported files will not match the stat info in the /another/dir's index).

-Peff
Previous: Eli BarzilayNext: Jeff King
Message 2 of 6 in “Checking out on a different+partial directory”
  1. Eli BarzilayMay 17, 2010
  2. Jeff KingMay 22, 2010
  3. fix over-eager caching in sha1_file_nameJeff King, May 22, 2010
  4. remove over-eager caching in sha1_file_nameJeff King, May 22, 2010
  5. Junio C HamanoMay 26, 2010
  6. Eli BarzilayMay 27, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.