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

Re: Fwd: Re: git checkout -f branch doesn't remove extra files

From
Linus Torvalds <torvalds@osdl.org>
Date
Aug 13, 2005, 05:05 UTC
Message-ID
<Pine.LNX.4.58.0508122151120.19049@g5.osdl.org>
In-Reply-To
<20050813041737.GB25236@redhat.com>
On Sat, 13 Aug 2005, Dave Jones wrote:
Show 13 quoted lines
>
> My git snapshot creator that builds the hourly tarballs at
> http://www.codemonkey.org.uk/projects/git-snapshots/
> currently does an rsync, and then a checkout, and finally
> it cleans up by removing all the checked out files.
> It currently does this by hand, but on learning about
> this 'new' command, I thought, cool, now I can do..
> 
> git-ls-files | xargs rm -rf
> 
> however, this then leaves a bunch of empty subdirs, as
> git-ls-files doesn't list the subdirs by themselves in
> the output.  Am I missing some other option ?
Nope, you're not missing anything, except that you shouldn't do that.
"git-ls-files" is very nice for things like
	git-ls-files | xargs grep ....

but your example is not one of them. Not without options, and not _with_ strange options.

Your example is an example of just not doing it the right way.
If you really want a temporary tree, what you do is something like
	git-checkout-cache --prefix=tmp-dir/ -f -a
and when you're done, you just do
	rm -rf tmp-dir
and you're done.

NOTE NOTE NOTE! In the above, the order of the parameters is really really important! "-a" takes effect when it is seen, so it needs to be last. Also, the "--prefix" thing really _really_ needs the slash at the end, because it's literally used to prefix the pathname.

HOWEVER, if all you want to do is just a tar-file, then there's a better solution. It's called

	snap=git-snapshot-$(date +"%Y%m%d")
	git-tar-tree HEAD $snap | gzip -9 > $snap.tar.gz
which is even easier, and a hell of a lot more efficient.

Git actually has a _lot_ of nifty tools. I didn't realize that people didn't know about such basic stuff as "git-tar-tree" and "git-ls-files".

		Linus
Previous: Dave JonesNext: Dave Jones
Message 2 of 8 in “Fwd: Re: git checkout -f branch doesn't remove extra files”
  1. Dave JonesAug 13, 2005
  2. Linus TorvaldsAug 13, 2005
  3. Dave JonesAug 13, 2005
  4. Linus TorvaldsAug 13, 2005
  5. Linus TorvaldsAug 13, 2005
  6. Petr BaudisAug 13, 2005
  7. Sergey VlasovAug 13, 2005
  8. Petr BaudisAug 13, 2005

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.