Last Updated: February 25, 2016
· henriqueso

Partial commits with git add -p

I hope you're familiar with the benefits of small commits.

As a general rule, you should try to split your changes into small logical steps, and commit each of them. They should be consistent, working independently of any later commits, pass the test suite, etc. - gitworkflows

If you are not used to writing small pieces of code and committing 'em often, you still have the option of patching 'em later with git add -p.

This command will open an interactive mode where you can review each change you've made and then select just what you want to add to the staging area for committing.

You can watch a very good explanation about it on John Kary's post.

3 Responses
Add your response


over 1 year ago ·

I agree with you, also another tips is that even once you are doing
git add -p
if you find a big chunk of code, you can press the "s" key to split the chunk in even a smaller chunk.

I like to have an alias for git patch,
$ git config --global alias.addp add -p
which allows me to just say
$ git addp

over 1 year ago ·

Well said! Thank you for your comment. Appreciate it.

over 1 year ago ·