Documentation / howto / rebase-and-edit.txton commit Merge master changes into rc. (da27f4f)
   1Date:   Sat, 13 Aug 2005 22:16:02 -0700 (PDT)
   2From:   Linus Torvalds <torvalds@osdl.org>
   3To:     Steve French <smfrench@austin.rr.com>
   4cc:     git@vger.kernel.org
   5Subject: Re: sending changesets from the middle of a git tree
   6
   7On 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
  13Let me clarify.
  14
  15You can entirely _drop_ old branches, so commits may be immutable, but
  16nothing forces you to keep them. Of course, when you drop a commit, you'll 
  17always end up dropping all the commits that depended on it, and if you 
  18actually got somebody else to pull that commit you can't drop it from 
  19_their_ repository, but undoing things is not impossible.
  20
  21For example, let's say that you've made a mess of things: you've committed
  22three commits "old->a->b->c", and you notice that "a" was broken, but you
  23want 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
  48and you've now re-applied (and possibly edited the comments) the two
  49commits b/c, and commit "a" is basically gone (it still exists in the
  50"broken" branch, of course).
  51
  52Finally, check out the end result again:
  53
  54        # Look at the new commit history
  55        gitk --all
  56
  57to see that everything looks sensible.
  58
  59And then, you can just remove the broken branch if you decide you really 
  60don'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
  68And yeah, I'm sure there are other ways of doing this. And as usual, the 
  69above is totally untested, and I just wrote it down in this email, so if 
  70I've done something wrong, you'll have to figure it out on your own ;)
  71
  72                        Linus
  73-
  74To unsubscribe from this list: send the line "unsubscribe git" in
  75the body of a message to majordomo@vger.kernel.org
  76More majordomo info at  http://vger.kernel.org/majordomo-info.html
  77
  78