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
7 On Sat, 13 Aug 2005, Linus Torvalds wrote:
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
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.
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
25 # Create a branch "broken" that is the current code
29 # Reset the main branch to three parents back: this
30 # effectively undoes the three top commits
34 # Check the result visually to make sure you know what's
38 # Re-apply the two top ones from "broken"
40 # First "parent of broken" (aka b):
41 git-diff-tree -p broken^ | git-apply --index
42 git commit --reedit=broken^
44 # Then "top of broken" (aka c):
45 git-diff-tree -p broken | git-apply --index
46 git commit --reedit=broken
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).
52 Finally, check out the end result again:
54 # Look at the new commit history
57 to see that everything looks sensible.
59 And then, you can just remove the broken branch if you decide you really
62 # remove 'broken' branch
63 rm .git/refs/heads/broken
65 # Prune old objects if you're really really sure
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 ;)
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