# Autosplit option for git add -p

4 messages from 2024-06-07 to 2024-06-08. Participants: Konstantin Tokarev, Christian Couder, Dragan Simic, Junio C Hamano.
Thread: https://gitlist.dev/t/61604

## Konstantin Tokarev, 2024-06-07 09:05

Subject: Autosplit option for git add -p
Message-ID: <20240607120530.74297526@yuvnserver>
URL: https://gitlist.dev/e/20240607120530.74297526%40yuvnserver

```
Hello all,

Is there any option in git to make `git add -p` split hunks by
default, just like 's' was pressed automatically? If no, how would one
implement such an option?

My use case: I've recently started working with big LaTeX document
having every paragraph as a single line. As a result, hunks quickly
become larger than screen, so that splitting is highly desirable.

Thanks.

```

## Christian Couder, 2024-06-08 10:43

Subject: Re: Autosplit option for git add -p
Message-ID: <CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ%40mail.gmail.com
In-Reply-To: <20240607120530.74297526@yuvnserver>

```
Hi,

On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> wrote:
>
> Hello all,
>
> Is there any option in git to make `git add -p` split hunks by
> default, just like 's' was pressed automatically? If no, how would one
> implement such an option?

It doesn't look like there is any option to do that. About
implementing it, it depends if it would be a command line option or a
config option.

Anyway I think you might want to take a look at the run_add_p()
function in "add-patch.c".

> My use case: I've recently started working with big LaTeX document
> having every paragraph as a single line. As a result, hunks quickly
> become larger than screen, so that splitting is highly desirable.

Best!

```

## Dragan Simic, 2024-06-08 10:47

Subject: Re: Autosplit option for git add -p
Message-ID: <2a50a861804727da14f6a440bc335178@manjaro.org>
URL: https://gitlist.dev/e/2a50a861804727da14f6a440bc335178%40manjaro.org
In-Reply-To: <CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ@mail.gmail.com>

```
Hello,

On 2024-06-08 12:43, Christian Couder wrote:
> On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> 
> wrote:
>> Is there any option in git to make `git add -p` split hunks by
>> default, just like 's' was pressed automatically? If no, how would one
>> implement such an option?
> 
> It doesn't look like there is any option to do that. About
> implementing it, it depends if it would be a command line option or a
> config option.

To me, a new command-line option would make more sense.  Though,
perhaps a new configuration option could also make sense when enabled
for particular repositories, but that could also trigger the main red
flag, which is that a repository configuration can change the user
experience, so I'm not sure it wouldn't be frowned upon.

> Anyway I think you might want to take a look at the run_add_p()
> function in "add-patch.c".
> 
>> My use case: I've recently started working with big LaTeX document
>> having every paragraph as a single line. As a result, hunks quickly
>> become larger than screen, so that splitting is highly desirable.

```

## Junio C Hamano, 2024-06-08 18:53

Subject: Re: Autosplit option for git add -p
Message-ID: <xmqqmsnvclle.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqmsnvclle.fsf%40gitster.g
In-Reply-To: <CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ@mail.gmail.com>

```
Christian Couder <christian.couder@gmail.com> writes:

> It doesn't look like there is any option to do that. About
> implementing it, it depends if it would be a command line option or a
> config option.

Having these alone make no sense to me.

I'd suggest extending the lowest level (i.e. interactive prompt
response) first so that a stronger 's' splits all hunks in the
current file.  It might be sufficient for the use case.

On top of that, it happens to be that when changes to _all_ paths
want to be split, it may prove handy to also have a command line
option.

But the reason why I am hesitant to endorse a command line option
that splits everything is because:

 (1) it is dubious to expect the user to _know_ that it makes sense
     to split all changes before starting "add -p" (and friends).

 (2) if the user gives such an option and then in the interactive
     session regrets that it was too much to split all the hunks, it
     is unclear how the user can easily recover (there is no "merge
     all hunks back to the original" operation).



```
