Interactively add content in git
Published
It’s often handy to add changes you’ve made to your local branch in git in a more interactive fashion. Sometimes the changes you have make more sense in multiple commits than one catch all commit.
It’s quite easy to do this in git and here’s how:
git add -p
The -p
flag say to add changes interactively, breaking cohesive changes up into chunks. Here’s roughly what it will look like:
Now that you see your changes, you have a few options:
y
– Add the given chunk.n
– Skip the given chunk (eg “next”).s
– Split the given chunk up into smaller chunks.q
– Stop adding chunks and exit out ofadd
.?
– See all the other available sub commands.
Hope that’s helpful.
Like this post?
Why don't you let me know on Twitter:
@danawoodman