I have a set of changes in stash@{4} that I would like to apply, but in such a way that the changes are merged into the working copy (or else a new commit) such that either version can be selected by a preprocessor symbol.
(This is a feature of the GNU diff and diff3 programs: see the --ifdef option.)
For instance a hunk like
@@ -123,7 +123,7 @@
 a
 b
 c
-foo
+bar
 d
 e
 f
is actually applied to the working file as
a
b
c
#ifdef SYM
bar
#else
foo
#endif
d
e
f
If SYM is defined, the text corresponds to the patched version, whereas if it is not defined, the text expands to the base version.
Perhaps this can be done with git merge, somehow telling git to use diff3 --ifdef=SYM for merging?
The obvious just struck me: patch has an --ifdef/-D option as well. 
git stash show -p stash@{4} | patch -p1 -D SYMBOL
Done!
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