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

Re: Howto update a 'dirty' entry in the cache from the object database

From
Linus Torvalds <torvalds@osdl.org>
Date
May 4, 2005, 17:23 UTC
Message-ID
<Pine.LNX.4.58.0505041014510.2328@ppc970.osdl.org>
In-Reply-To
<20050504142351.GL18380@cip.informatik.uni-erlangen.de>
On Wed, 4 May 2005, Thomas Glanzmann wrote:
Show 5 quoted lines
>
> I edited a bunch of files and notice that I want to revert back one of
> the files to the original one (the one that comes with HEAD). But I
> already updated the cache. Is there a way to 'patch' the cache with the
> original file.
Absolutely.
You can do it several ways. The easiest one is
	git-read-tree -m HEAD
	git-checkout-cache -f filename

but this means that you revert your entire index file to the old HEAD information, so you'll need to do git-update-cache on the files that you changed.

So:
> Or do I need todo a read-tree into a temporary index
> file. Check out the one file from this alternate index file and use
> update-cache to update my original index file?

Yes. If you want to touch just that one file, and you actually _want_ to save all the other index information updates except for this one file. If so, you can do

	# read a new index file with the HEAD information
	GIT_INDEX_FILE=tmp-index git-read-tree HEAD
	# check out just the one file you want to have
	GIT_INDEX_FILE=tmp-index git-checkout-cache -f filename
	# remove the now useless temporary index
	rm tmp-index
	# update your _real_ index file with the file information
	git-update-cache filename

and you're done - you've now updated only that _one_ file in your working area, and you've re-set the index file for that entry.

And yes, scripting it so that you don't make stupid mistakes is probably a good idea. For exmple, if you misspell GIT_INDEX_FILE (like I did when I write that at first), you'd have reverted your real index file after all.

In other words, the git core certainly is very flexible and can easily do what you want, but it's also certainly very very easy to screw up with.

		Linus
Previous: Thomas GlanzmannNext: Junio C Hamano
Message 2 of 4 in “Howto update a 'dirty' entry in the cache from the object database”
  1. Thomas GlanzmannMay 4, 2005
  2. Linus TorvaldsMay 4, 2005
  3. Junio C HamanoMay 4, 2005
  4. Thomas GlanzmannMay 4, 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.