Posts

Showing posts with the label git

Git Stash Specific Changes

Use `git stash push`. You can give it specific files to stash or use `-p` to select specific changes within files. I don't know how long this has been a command for. According to the manpage, this is a more featureful replacement for `git stash save`.

'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.