git add –patch

This command allows you to concisely add lines of code to a commit.

git add --patch

select lines of code

You will then select lines of code that matter to the commit. Each sections of code shown is a hunk.

  • select ‘y’ to agree to add hunk
  • select ‘n’ to ignore hunk

split hunks

If there is a line of code that does not fit in the hunk. You can “split” the code to break the hunk selection in a more granular way.

Press ‘s’ if you see a line of code that should not be in your desired hunk and continue with the selection process.

write your commit message

git commit

references