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:27 UTC
Message-ID
<7vy7aatfck.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<vpqfxwi5ljf.fsf@bauges.imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 9 quoted lines
> "Paolo Ciarrocchi" <paolo.ciarrocchi@gmail.com> writes:
>
>> Yes it helps but I still wonder whether thereis a "simpler" way to achive that.
>> Is it possible to split a patch selecting the hunk in git gui or any
>> other graphical
>> tool?
>
> You can apply the patch without commiting it, and them make several
> partial commits, by right-click "stage hunk for commit" in git-gui.

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).

Ideally, once you have a perfect state (i.e. the shape of the tree recorded by the last commit in your "split" series), you should be able to make a commit, and walk backwards, removing the fanciest "finishing touches" changes from the work tree files, test it, and record it as a new commit between where you are and one commit before it. A possible workflow could be:

	$ work work work, now it is perfect.
	$ git commit -a -m 'Now it is perfect'
        $ edit away the fanciest bits
        $ test test, the basics still work.
        $ git commit --splice -a -m 'Almost there'

And the last "git commit --splice" would record the tree object as a commit, whose parent is the parent of the current HEAD, and record the tree of the current HEAD as a (rewritten) commit that is a child of that commit.

Graphically, you would start from (X is "the perfect commit"):
	---o-------X

then "--splice" would create a new commit "W" and record the same tree as X as a new commit X' that is a child of W:

             .--W---X'
            /
	---o-------X
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.

Previous: Matthieu MoyNext: Junio C Hamano
Message 5 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.