What's cooking
[git/spearce.git] / ResettingPaths.txt
blobd101814e00ce876bac58e6cd153b73eed7c1cddc
1 From: Junio C Hamano <junkio@cox.net>
2 Subject: Resetting paths
3 Date: Thu, 09 Feb 2006 20:40:15 -0800
4 Message-ID: <7vlkwjzv0w.fsf@assigned-by-dhcp.cox.net>
5 Content-Type: text/plain; charset=us-ascii
6 Return-path: <git-owner@vger.kernel.org>
8 While working on "assume unchanged" git series, I found one
9 thing missing from the current set of tools.
11 While I worked on parts of the system that deals with the cached
12 lstat() information, I needed a way to debug that, so I hacked
13 ls-files -t option to show entries marked as "always matches the
14 index" with lowercase tag letters.  This was primarily debugging
15 aid hack.
17 Then I committed the whole thing with "git commit -a" by
18 mistake.  In order to rewind the HEAD to pre-commit state, I can
19 say "git reset --soft HEAD^", but after doing that, now I want
20 to unupdate the index so that ls-files.c matches the pre-commit
21 HEAD.
23 "git reset --mixed" is a heavy-handed tool for that.  It reads
24 the entier index from the HEAD commit without touching the
25 working tree, so I would need to add the modified paths back
26 with "git update-index".
28 The low-level voodoo to do so for this particular case is this
29 single liner:
31         git ls-tree HEAD ls-files.c | git update-index --index-info
33 Have people found themselves in similar need like this?  This
34 could take different forms.
36  * you did "git update-index" on a wrong path.  This is my
37    example and the above voodoo is a recipe for recovery.
39  * you did "git add" on a wrong path and you want to remove it.
40    This is easier than the above:
42         git update-index --force-remove path
44  * you did the above recovery from "git add" on a wrong path,
45    and you want to add it again.  The same voodoo would work in
46    this case as well.
48         git ls-tree HEAD path | git update-index --index-info
50 We could add "git reset path..." to reduce typing for the above,
51 but I am wondering if it is worth it.
53 BTW, this shows how "index centric" git is.  With other SCM that
54 has only the last commit and the working tree files, you do not
55 have to worry any of these things, so it might appear that index
56 is just a nuisance.  But if you do not have any "registry of
57 paths to be committed", you cannot do a partial commit like what
58 I did above ("commit changes to all files other than
59 ls-files.c") without listing all the paths to be committed, or
60 fall back on CVS style "one path at a time", breaking an atomic
61 commit, so there is a drawback for not having an index as well.