How to stage chunks of a file?

1,300 views
Skip to first unread message

James Johnston

unread,
Jan 26, 2012, 6:22:36 PM1/26/12
to gitext...@googlegroups.com
In Git, I can interactively stage chunks of a file by running the following:

git add -p <filename>

How do I do this in Git Extensions without having to drop to the command line? I can't seem to find a menu option or button that will do that from the Commit dialog.

Oliver Friedrich

unread,
Jan 26, 2012, 6:35:04 PM1/26/12
to gitext...@googlegroups.com
In the commit dialog, select some lines and via context menu choose to "stage selected lines":

stage-selected.png

Cheers, Oliver
~~~~~~~~~~~~~
stage-selected.png

Mateusz Pusz

unread,
Jan 27, 2012, 1:13:40 AM1/27/12
to gitext...@googlegroups.com

Yes, that option is great but I really miss here "Stage/Unstage whole chunk" option that is available in git gui. If you have a lot of changes in a file selection on per-chunk basis is much more efficient.

Would it be possible to add such a feature?

Best

Mat

stage-selected.png

James Johnston

unread,
Jan 27, 2012, 11:04:41 AM1/27/12
to gitext...@googlegroups.com

Thanks everyone for the tip on staging only some lines.  This should get me by without having to drop to the command line.  For further improvement, I think it’s worthwhile to break this down into 3 possible chunk-handling options:

 

·         Staging only some lines/chunks

·         Unstaging only some lines/chunks

·         Resetting/discarding changes to only some lines/chunks

 

Each seems to have deficiencies/inconsistencies in how each is done in Git Extensions; I’ll address them below in a feature request:

 

·         Staging only some lines:  the “stage selected lines” feature as pointed out seems to work really well.  The reason I did not find it is because there is no “Stage chunk of file” menu option next to the “Reset chunk of file” option when right-clicking the filename in the upper-left corner of the window.  There needs to be:

o   A new “Stage chunk of file” option when right-clicking the filename.  When this is clicked, it will invoke the “git add -p" command for interactive staging in a console window – similar to “Reset chunk of file”.

o   A new “Stage whole chunk” option when right-clicking a chunk in the text editor, just as Mateusz Pusz suggests.

·         Unstaging only some lines:

o   Again, there needs to be an “Unstage chunk of file” menu option when right-clicking a staged filename.  Again, it would invoke “git reset -p” to interactively unstage in a console window.

o   A new “Unstage whole chunk” option when right-clicking a chunk in the text editor, just as Mateusz Pusz suggests.

o   (While I’m at it, there needs to be a menu to begin with when right-clicking a staged filename… similar to when right-clicking an unstaged file.  For example, “View file history”, “Open With Difftool”, “Copy Filename” seem like some options that might be useful on staged files as well).

·         Resetting only some lines.  I assume the workflow should be that you must unstage first before resetting, i.e. permanently discarding changes to a file.  (I assume this because the GUI currently offers no functional way to do this to any staged file – in whole or in part).

o   A new “Reset whole chunk” option when right-clicking a chunk in the text editor when viewing a diff for an unstaged file; would be disabled if viewing a staged file.

o   The “Reset selected line(s)” option when right-clicking in the text editor when viewing a diff for an unstaged file is disabled.  It needs to be enabled in this scenario, just as the “Stage selected lines” option is enabled.  Currently the only way to do this is to use the “Reset chunk of file” option and do it interactively in the console.

o   The “Reset selected line(s)” option when right-clicking in the text editor when viewing a diff is enabled, but clicking it yields an error message.  It really should be disabled in this scenario since you need to unstage first.

 

The end result I think would be much more consistent:  right-click a filename to invoke console for interactive staging/unstaging/resetting.  (Sometimes it’s nice to just be walked through this change-by-change).  Select some lines and right-click them to stage/unstage/reset them.  Or right-click a chunk to stage/unstage/reset it.

 

Should I start a new issue in the issue tracker for this?  Any further thoughts on this?

 

James

image001.png

Donatas Mačiūnas

unread,
Sep 16, 2012, 1:39:21 PM9/16/12
to gitext...@googlegroups.com
If you don't mind building a custom build, you may try my implementation of this feature https://github.com/mdonatas/gitextensions/tree/InteractiveAdd



It will open GitBash with interactive add for the file. Granted it's not a native GitExtensions support for interactive add but it works perfectly for me.

Donatas

Adrian Codrington

unread,
Sep 16, 2012, 8:34:02 PM9/16/12
to gitext...@googlegroups.com
Unless I'm mistaken, Git Extensions already has this feature - in the commit window, select the part of the diff you want to stage and right-click. The context menu should contain and entry to do what you want.

However, I think this functionality has been broken in recent versions, as it has recently started failing on my machine. Perhaps one of the regular devs could comment - I haven't looked into it myself.

Donatas Mačiūnas

unread,
Sep 17, 2012, 5:27:23 AM9/17/12
to gitext...@googlegroups.com
Yes, there is limited support for that. But with GitBash you can edit the chunk before staging and if there are many changes in a file it's a bit faster to go through them via command line. Admittedly for staging just a line or two is faster from git extensions UI.
Reply all
Reply to author
Forward
0 new messages