1

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).

bgoodr
  • 2,744
  • 1
  • 30
  • 51
  • 1
    So to be clear, you're looking for a solution that does not involve shell scripting, or would you be okay with one that does? – bk2204 Oct 14 '20 at 01:28
  • @bk2204 Ok, well, only if it does not require use of `rpm`, `yum`, or `apt`. E.g. something using what is usually installed on a stock RHEL or CentOS machine. Because if we get into using tooling that is outside of Git, we have to talk about operating systems, versions, etc. etc. – bgoodr Oct 14 '20 at 02:58
  • 1
    This answer seem to address your request - https://stackoverflow.com/a/7149602/4158037. Please check. – Prasanna Oct 14 '20 at 11:57
  • @Prasanna I think that is _highly_ likely to be the answer to my question. I will read that thoroughly. Thank you. – bgoodr Oct 15 '20 at 01:51
  • So https://stackoverflow.com/a/7149602/4158037 is sufficient as an answer to this one. Perhaps it could be closed as a dup, but I'm not going to investigate how, because there is not efficient facility for indicating such by the OP. – bgoodr Nov 08 '20 at 15:28

0 Answers0