Skip to contentSkip to conversation

how to split a hunk

DISCUSSION bill lam 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore

bill lam

author
#0 lore raw

There are occasions where diff of a file is

- aaaa
+ bbbb
+ cccc

I want to add lines bbbb and cccc as separated commits, but git-add -p seem cannot further split this hunk. Do I have no choice but to edit it by hand and commit the bbbb and then edit the file to add back the cccc?

Signature · 4 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
#1 lore raw
Quoted 10 lines · bill lam

There are occasions where diff of a file is

- aaaa
+ bbbb
+ cccc

I want to add lines bbbb and cccc as separated commits, but git-add -p seem cannot further split this hunk. Do I have no choice but to edit it by hand and commit the bbbb and then edit the file to add back the cccc?

There's also the 'git add -p' [e]dit feature, which pops up the patch in an editor. There are instructions in that file, but in this case, you can simply remove one of the additions.

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch
author
#2 lore raw
Quoted 3 lines · Thomas Rast

There's also the 'git add -p' [e]dit feature, which pops up the patch in an editor. There are instructions in that file, but in this case, you can simply remove one of the additions.

Thank you for pointing out the [e], incidentally after trying it, I also noticed and tried the add -e which belongs to a similar format.

Signature · 4 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
#3 lore raw
In reply to bill lam
Quoted 11 lines · bill lam

There are occasions where diff of a file is

- aaaa
+ bbbb
+ cccc

I want to add lines bbbb and cccc as separated commits, but git-add -p seem cannot further split this hunk. Do I have no choice but to edit it by hand and commit the bbbb and then edit the file to add back the cccc?

I like to use "git gui" for this. This allows you to pick individual lines to commit. I really like the "git gui" interface for staging/unstaging changes and making a series of commits.

-Geert

author
#4 lore raw
Quoted 3 lines · Geert Bosch

I like to use "git gui" for this. This allows you to pick individual lines to commit. I really like the "git gui" interface for staging/unstaging changes and making a series of commits.

Thank you suggestion. However I did not use git-gui/gitk or have tcl installed.

Signature · 4 lines
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3