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 --patch, git add will show you the diff file divided in hunks and ask whether to stage it or not.

Stage this hunk [y,n,q,a,d,/,j,J,k,K,g,e,?]?

The options are documented by the ? answer and are:

y - stage this hunk
n - do not stage this hunk
q - quit; do no stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

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.