Committing part of a file
As every human who has done some programming you tend to do the real work when in the zone. Time flyies and code has been written, lots of code in lots of files.
there is no way this work fits in one commit
Pondering what to do? A round of copy-paste-commit? Stash it and rewrite with commits somewhere in between? Editing the diff file by hand?
The best solution is to add part of your file, commit that and iterate until done; this can be done with
git add --patch.
When used with option
git add will show you the diff file divided in hunks and ask whether to stage it or not.
The options are documented by the
? answer and are:
What I loved most of this command is the
e (edit) option, it opens your text editor and you can remove added lines (a green
+ leading) by removing them from the hunk, remove deleted lines (a red
- leading) by removing the leading red
- and you are done. Save and it prompts what to do with tne next hunk.
This is granular precision and exactly what I was looking for, you can edit the diff file in interactive mode with Git helping you.