I want to split a commit into two commits: contentful changes & whitespace changes, though every solution I've found only applies if a line contains exclusively whitespace changes.
In the following there's an irrelevant whitespace change and a new argument added to a function:
$ git diff -U0
diff --git a/blah.h b/blah.h
--- a/blah.h
+++ b/blah.h
@@ -1, +1 @@
-void blah();
+void blah(int x);
The best I've found is this:
$ git diff -w --word-diff-regex=[^[:space:]]
diff --git a/blah.h b/blah.h
--- a/blah.h
+++ b/blah.h
@@ -1, +1 @@
void blah({+int x+});
... but so far as I can tell git-apply
cannot consume that as input.
I almost had myself convinced this may not be possible, arguing that git would need contextual information to know whether it's a meaninful change, eg:
... but git will happily ignore all whitespace changes as long as you don't introduce any other changes (in some neighborhood of the relevant lines).
I'm sure there exist other tools capable of doing what I want (or something close to it), though in this situation I cannot just download whatever I want to take care of the problem. Nevertheless, feel free to post answers of that stripe as they may help others in the future.
I believe my best option is to reformat the code before the changes get applied / commit / reformat the changed code / commit and live with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With