Is there a way, short of manual changes using scripts, text editors, etc., using Git commands, to take a current set of changes that are either already in the cache, or not yet in the cache, and git commit
only those lines that have changed non-whitespace characters?
A suitable answer may involve first git commit
-ing the changes, and then using git rebase
with various options similar in spirit to --whitespace=fix
.
I observe that using the git apply
options, or the associated git rebase
options that relay to git apply
, of --whitespace=fix
is not the answer, because of this paragraph in the git-apply
man-page:
--whitespace=<action>
When applying a patch, detect a new or modified line that has whitespace errors. What are considered whitespace errors is controlled by
core.whitespace configuration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character
that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.
I've verified this is the case with a git rebase --whitespace-fix @~
command on commit, on HEAD
, that has indentation whitespace changes (specifically fixing indentation that has a space followed by a TAB): The lines that did change indentation were still included.
Thus the answer to How to remove white space file before commit and upload on git is not the answer to this question, unfortunately.
The reason: I need to first do a commit that contains "real changes" that do not contain changes to indentation. At a later point in time, I might or might not choose to re-indent the entire file (removing embedded TABS in indentation, too) and check that in as a commit. I do not desire to do the re-indentation change to the file prior to the commit containing the "real changes". I do not want to first reindent the whole file, commit that, and then subsequently apply the changes: I already know that is a workaround, but that is not my question.
(In case it matters: I'm currently using git version 2.28.0).