Re:Oh shit, git: Getting myself out of bad situations
by YoyoyoPCP on Monday December 18, 2017 @12:19PM
(#15953264)
You use the 'e' option which allows you to edit the hunk. Remove the minus sign or the entire line with a '+'
Re:Oh shit, git: Getting myself out of bad situations
by deragent on Monday December 18, 2017 @12:21PM
(#15953290)
Within 'git add -p' when you get to the hunk that you want to edit (split down to single lines), press 'e'. This will open an editor (vim in my case) which lets you edit the diff manually.
In there you can remove added lines (prefixed by '+') by removing them, and re-adding removed lines (prefixed by '-') by replacing the '-' with a space ' '.
Re:Oh shit, git: Getting myself out of bad situations
by tigershark on Monday December 18, 2017 @02:48PM
(#15954811)
And how is this faster/better than selecting a line with the mouse and pressing s without opening any other editor?
Re:Oh shit, git: Getting myself out of bad situations
by RandomException on Monday December 18, 2017 @03:04PM
(#15954953)
Do it in Vim (or emacs for those weirdos out there) and you're done before you would've even reached the mouse :)
Re:Oh shit, git: Getting myself out of bad situations
by gknoy on Monday December 18, 2017 @06:18PM
(#15956348)
Sometimes your changes are across multiple files, and it's easier to say, "yes, yes, yes, yes, split, no, no, yes, ..."
Re:Oh shit, git: Getting myself out of bad situations
by lfrb on Monday December 18, 2017 @12:21PM
(#15953288)
You can use 's' to split a hunk but it would indeed not work if you want to split two consecutive lines.
You can also use 'e' option to edit the hunk to e.g. remove one of the added line.
Nothing as easy as clicking a line in a GUI though.
E.g. if you have two consecutive lines changed, it's not possible to split them, they are one "hunk".
(Waiting for someone to chime in with how to split a hunk and change my life).