Replace C99 array initializers with code.
[git.git] / Documentation / howto / rebase-and-edit.txt
1 Date:   Sat, 13 Aug 2005 22:16:02 -0700 (PDT)
2 From:   Linus Torvalds <torvalds@osdl.org>
3 To:     Steve French <smfrench@austin.rr.com>
4 cc:     git@vger.kernel.org
5 Subject: Re: sending changesets from the middle of a git tree
6
7 On Sat, 13 Aug 2005, Linus Torvalds wrote:
8
9 > That's correct. Same things apply: you can move a patch over, and create a 
10 > new one with a modified comment, but basically the _old_ commit will be 
11 > immutable.
12
13 Let me clarify.
14
15 You can entirely _drop_ old branches, so commits may be immutable, but
16 nothing forces you to keep them. Of course, when you drop a commit, you'll 
17 always end up dropping all the commits that depended on it, and if you 
18 actually got somebody else to pull that commit you can't drop it from 
19 _their_ repository, but undoing things is not impossible.
20
21 For example, let's say that you've made a mess of things: you've committed
22 three commits "old->a->b->c", and you notice that "a" was broken, but you
23 want to save "b" and "c". What you can do is
24
25         # Create a branch "broken" that is the current code
26         # for reference
27         git branch broken
28
29         # Reset the main branch to three parents back: this 
30         # effectively undoes the three top commits
31         git reset HEAD^^^
32         git checkout -f
33
34         # Check the result visually to make sure you know what's
35         # going on
36         gitk --all
37
38         # Re-apply the two top ones from "broken"
39         #
40         # First "parent of broken" (aka b):
41         git-diff-tree -p broken^ | git-apply --index
42         git commit --reedit=broken^
43
44         # Then "top of broken" (aka c):
45         git-diff-tree -p broken | git-apply --index
46         git commit --reedit=broken
47
48 and you've now re-applied (and possibly edited the comments) the two
49 commits b/c, and commit "a" is basically gone (it still exists in the
50 "broken" branch, of course).
51
52 Finally, check out the end result again:
53
54         # Look at the new commit history
55         gitk --all
56
57 to see that everything looks sensible.
58
59 And then, you can just remove the broken branch if you decide you really 
60 don't want it:
61
62         # remove 'broken' branch
63         rm .git/refs/heads/broken
64
65         # Prune old objects if you're really really sure
66         git prune
67
68 And yeah, I'm sure there are other ways of doing this. And as usual, the 
69 above is totally untested, and I just wrote it down in this email, so if 
70 I've done something wrong, you'll have to figure it out on your own ;)
71
72                         Linus
73 -
74 To unsubscribe from this list: send the line "unsubscribe git" in
75 the body of a message to majordomo@vger.kernel.org
76 More majordomo info at  http://vger.kernel.org/majordomo-info.html
77
78