Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert stash to working change delimited by #ifdef SYM

Tags:

git

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?

like image 654
Kaz Avatar asked May 20 '14 13:05

Kaz


1 Answers

The obvious just struck me: patch has an --ifdef/-D option as well.

git stash show -p stash@{4} | patch -p1 -D SYMBOL

Done!

like image 54
Kaz Avatar answered Oct 11 '22 19:10

Kaz