Search code examples
gitmsysgit

Committing partial Hunks in Git


If I made two logical changes, which is continuous in code. Git shows it as one single hunk while adding interactively.

Is there a way to specifically add only few lines in a hunk, during add --patch?


Solution

  • The git add --patch mode has option for splitting an individual hunk or editing an individual hunk.

    git add --patch:

    s - split the current hunk into smaller hunks
    e - manually edit the current hunk
    

    Wouldn't that solve your issue regarding your continuous set of lines?

    After adding partials to commit, User should use ONLY git commit to commit, using git commit -a or using commit with all files flag ignores added partial and commits all staged files.