threads / discuss / 25181

staging specific lines out of a hunk for a commit

Subject: staging specific lines out of a hunk for a commit

## tl;dr

6 messages between Sep 21, 2010 and Sep 21, 2010.

replies: 5people: 4as markdown or json

Graeme Geldenhuys· Sep 21, 2010, 10:40 UTC · lore
Hi,

I know 'git gui' has this cool feature where you can stage one line at a time. This is really handy, but also very annoying, if you have a large piece of code you want to commit.

eg: I have a single hunk, which can't be split into smaller hunks because it is all new code. But that hunk fixes a few bugs, or introduces a few new features.

Is there a way to use 'git add -i' or 'git add -p' or 'git gui' and tell it to add for example lines 5-20 of the hunk to the index? Currently with 'git gui', I have to right click and select 'Stage line for commit' 15+ times! :-(

Maybe 'gui gui' can be enhance (don't know if development work is continuing on gui gui') to use the same feature as in the "unstaged changes" area of the UI. There you can simply click the icon next to the file name to add that file. Maybe the same could be implemented to the "diff" area of the UI. Simply click the first column in the diff area (where the '+' or '-' or ' ' appears), to add those lines to the index. This will make adding or removing line to/from a commit so much quicker and easier than the popup menu.

I'm using git-gui 0.12.0.64 and git version 1.7.0.4.
-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net:8080/fpgui/
Bert Wesarg· Sep 21, 2010, 10:52 UTC · re: Graeme Geldenhuys · lore

Re: staging specific lines out of a hunk for a commit

Hi,

On Tue, Sep 21, 2010 at 12:40, Graeme Geldenhuys <graemeg.lists@gmail.com> wrote:

Show 14 quoted lines
> Hi,
>
> I know 'git gui' has this cool feature where you can stage one line at
> a time. This is really handy, but also very annoying, if you have a
> large piece of code you want to commit.
>
> eg: I have a single hunk, which can't be split into smaller hunks
> because it is all new code. But that hunk fixes a few bugs, or
> introduces a few new features.
>
> Is there a way to use 'git add -i' or 'git add -p' or 'git gui' and
> tell it to add for example lines 5-20 of the hunk to the index?
> Currently with 'git gui', I have to right click and select 'Stage line
> for commit' 15+ times! :-(

Just select the lines you would like to add, and than you can stage them at once.

>
> I'm using git-gui 0.12.0.64 and git version 1.7.0.4.
But I don't know since when this feature is available.
Bert
>
> --
> Regards,
>   - Graeme -
Graeme Geldenhuys· Sep 21, 2010, 11:00 UTC · re: Bert Wesarg · lore

Re: staging specific lines out of a hunk for a commit

On 21 September 2010 12:52, Bert Wesarg wrote:
>
> Just select the lines you would like to add, and than you can stage
> them at once.

I tried that last night on my home laptop and it didn't work. Trying it now at work, it indeed does work. Clearly my git versions are different - when I thought they were the same. Thanks for the help.

-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net:8080/fpgui/
Matthieu Moy· Sep 21, 2010, 11:31 UTC · re: Graeme Geldenhuys · lore

Re: staging specific lines out of a hunk for a commit

Graeme Geldenhuys <graemeg.lists@gmail.com> writes:
Show 8 quoted lines
> On 21 September 2010 12:52, Bert Wesarg wrote:
>>
>> Just select the lines you would like to add, and than you can stage
>> them at once.
>
> I tried that last night on my home laptop and it didn't work. Trying
> it now at work, it indeed does work. Clearly my git versions are
> different - when I thought they were the same. Thanks for the help.

Otherwise, "git add -p", 'e' for 'e'dit, and delete the parts you don't want.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Graeme Geldenhuys· Sep 21, 2010, 11:44 UTC · re: Matthieu Moy · lore

Re: staging specific lines out of a hunk for a commit

On 21 September 2010 13:31, Matthieu Moy wrote:
>
> Otherwise, "git add -p", 'e' for 'e'dit, and delete the parts you
> don't want.

Ha, I was wondering about that, but wasn't sure if it would be accepted or cause problems. Thanks for the tip.

-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net:8080/fpgui/
Jonathan del Strother· Sep 21, 2010, 11:09 UTC · re: Graeme Geldenhuys · lore

Re: staging specific lines out of a hunk for a commit

On 21 September 2010 11:40, Graeme Geldenhuys <graemeg.lists@gmail.com> wrote:
Show 15 quoted lines
> Hi,
>
> I know 'git gui' has this cool feature where you can stage one line at
> a time. This is really handy, but also very annoying, if you have a
> large piece of code you want to commit.
>
> eg: I have a single hunk, which can't be split into smaller hunks
> because it is all new code. But that hunk fixes a few bugs, or
> introduces a few new features.
>
> Is there a way to use 'git add -i' or 'git add -p' or 'git gui' and
> tell it to add for example lines 5-20 of the hunk to the index?
> Currently with 'git gui', I have to right click and select 'Stage line
> for commit' 15+ times! :-(
>

If you happen to be on a Mac, gitx allows you to select the lines you're interested in with the mouse and stage them.

← back to recent threads