From: Linus Torvalds Date: Tue, 22 Nov 2005 05:23:45 GMT Subject: Re: index manipulation -- how? Message-ID: In-Reply-To: <20051122050337.46450.qmail@web31808.mail.mud.yahoo.com> On Mon, 21 Nov 2005, Luben Tuikov wrote: > > How do I reverse a _single_ "git-update-index" operation? > Be it --add or just an update. An "add" is easy enough to undo: just do a git-update-index --force-remove filename which will remove the entry from the index even if the file on your filesystem still remains (so you can "git add" it later when you do want to commit it). For a file that you had in your old index, but you've updated (either mode or SHA1), you need to figure out what the old mode/sha1 was. USUALLY this would be just the state that you still have in your HEAD tree, but if you want to go back to something else, you'd need to figure out what that was. If it's the "last commit" state (ie just your HEAD state), then do git-ls-tree HEAD filename which will show you the info, and then you do git-update-index --cacheinfo filename from that state. You could obviously script something like "git-downdate-index": #!/bin/sh filename="$1" tree_info=$(git-ls-tree HEAD -- "$filename") if [ -z "$tree_info" ]; then git-update-index --force-remove -- "$filename" else echo "$tree_info" | while read mode type sha1 name; do git-update-index --cacheinfo "$mode" "$sha1" "$filename" done fi but the above is totally untested, and "git-downdate-index" is a really sucky name too, so you'd need to rename it and test whether it does what you want. Hmm? Linus