Git add in patch mode

January 10th, 2013 § 0 comments

Recently I ran into a situation that I need to include only some part of changes I done to that file, but I can’t discard the rest of the changes. git add will add whole changes to the commit.

To avoid that I used git add -p . 

Git add help

-p or –patch option will iterate though each changes (hunks) in that file and ask us whether we want to stage those changes to commit.

Git add a hunk

If you wanna add this hunk reply with “y” or “n“. if you wanna check all other option please reply with “?“. A reply with “?” will return the whole help for the patch mode.

Stage the hunk

Now you can stage only the needed hunk and commit.

Happy Versioning 😉

Revath S Kumar [RSK]

- Rubyist / JavaScripter - Yeoman Team member - Open source enthusiast - Blogger @ PHPRepo and - Coder @ Whatznear - Google fanboy - jQuery lover

More Posts - Website - Twitter - Facebook - LinkedIn - Pinterest - Google Plus - YouTube