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

Feature Request: Custom split location for `git add --patch`

From
DGDennis van Gerwen <dvg@xs4all.nl>
Date
Jun 16, 2022, 10:19 UTC
Message-ID
<da79cc66-42a0-2563-d09b-fbc0ad5b28bd@xs4all.nl>
L.S.

Please consider this feature request for interactive staging in patch mode, using [`git add --patch`][1].

## Problem

If a hunk cannot be split automatically, the `s` (split) option disappears from the list of options, and we get:

 > (1/6) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? s
 > Sorry, cannot split this hunk
See for example these questions on StackOverflow: [2], [3]

I am aware that this problem can be solved by using the [`--edit` option][4] to edit the hunk, as explained in the docs under [editing patches][5].

However, if we have a large contiguous hunk, and we only want to split at one specific location, using `--edit` can be quite cumbersome, because (as far as I know) we need to edit all the lines that we do not want to stage.

## Feature request

Would it be possible to add a "custom split location" feature, allowing the user to specify where a contiguous hunk should be split?

Some options:
- Always show the `s` (split hunk) option, and let the user specify a 
line number if an automatic split cannot be made.
- Add a new [patch option][6], in addition to `s` (split hunk), to split 
any hunk at a custom location.
- Add a new operation for editing patches, for example "s" (in addition 
to "+", "-", and " "), indicating where to split (e.g. "split after this 
line"). This way the user only needs to modify a single line in edit mode.

I'm sure there are a lot of nasty details to consider, but I do think such a feature would be very convenient.

Thanks for your help,
Dennis

[1]: https://git-scm.com/docs/git-add#Documentation/git-add.txt---patch [2]: https://stackoverflow.com/q/6276752 [3]: https://stackoverflow.com/q/56892981 [4]: https://git-scm.com/docs/git-add#Documentation/git-add.txt---edit [5]: https://git-scm.com/docs/git-add#_editing_patches [6]: https://git-scm.com/docs/git-add#Documentation/git-add.txt-patch

Next: Johannes Schindelin
Message 1 of 3 in “Feature Request: Custom split location for `git add --patch`”
  1. Dennis van GerwenJun 16, 2022
  2. Johannes SchindelinJun 18, 2022
  3. Junio C HamanoJun 21, 2022

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.