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 .
-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.
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.
Now you can stage only the needed hunk and commit.
Happy Versioning 😉