'git add' Part of a File

It's the kind of thing you would assume is too good to be true. It's a more advanced feature and so most people don't get taught it when introduced to 'git'.

git add [-p | --patch]

I remember it as -p for partial, but never mind.

It brings up a small interface that displays one hunk of code at a time. The question mark command will explain how to use it. However it's not obvious that 'e' for 'edit' allows you to edit which changes are made rather than edit the changes themselves.

It opens up what looks like a 'git diff', where you remove changes you don't want to 'git add' by removing '+' lines or removing the '-' in front of lines to be taken away. i.e. choosing which '+' to add and which '-' to add.

Anyway if you're adding part of a file, if you have access to a GUI, it's going to be easier to do it that way.

Comments

Popular posts from this blog

VSC Vanishing Go Imports

Fix Controller Input when a Game Doesn't Use Steam Input

En Dash with ComposeKey (Shift+AltGr)