git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to split a patch

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 28, 2008, 10:40 UTC
Message-ID
<7vr6g2teqh.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vy7aatfck.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> Yes, and you can do the same with "git add -i".  These tools are
> not quite nice, as they encourage a wrong workflow of committing
> what you haven't had as a whole in the work tree.  By
> definition, you are making untested commits between your base
> commit (that presumably was tested well) and your final commit
> (that would also be tested well).
> ...
> There is no such tool yet, though.
> 
> The splitting you can do with "rebase -i" instead walks
> forwards.  That also lets you test before you make commits in
> each step.

Having said all that, what I tend to do in practice is something like this:

 (1) Prepare a perfect state (i.e. what to become the final
     commit in the series) in work tree.  Make a commit.  Let's
     say I was working on 'master' branch.
 (2) Checkout the state before the series.  If I currently have
     a three commit series that I want to split further, that
     would be HEAD~3.  If I just made a huge change without
     making intermediate commits, that would be HEAD~1:
     $ git checkout HEAD~3
 (3) Get the final state in the work tree, to decide what to put
     in and what to omit from the first in the series:
     $ git diff -R master | git apply --index
 (4) Use "git-add -i" to prepare what I want in the first
     commit.
     $ git add -i
 (5) When the index is in a good shape, drop all other changes
     from the work tree.  This is what I thought would be a good
     first commit:
     $ git diff -R | git apply
 (6) Test it.  Make corrections.  Perfect it.  Then commit.
     $ git commit
 (7) Go back to step (3), until the commit that I make in step
     (6) matches 'master'.
 (8) Reset 'master' with HEAD:
    $ git branch -f master HEAD
    $ git checkout master
Previous: Junio C HamanoNext: Mike Hommey
Message 6 of 11 in “How to split a patch”
  1. Paolo CiarrocchiJan 28, 2008
  2. Junio C HamanoJan 28, 2008
  3. Paolo CiarrocchiJan 28, 2008
  4. Matthieu MoyJan 28, 2008
  5. Junio C HamanoJan 28, 2008
  6. Junio C HamanoJan 28, 2008
  7. Mike HommeyJan 28, 2008
  8. Wincent ColaiutaJan 28, 2008
  9. Johannes SchindelinJan 28, 2008
  10. Wincent ColaiutaJan 28, 2008
  11. Boaz HarroshJan 28, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.