Convert stash to working change delimited by #ifdef SYM

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

  • Heroku deploy stopped working
  • Is 'git reset --hard Head~1' enough to undo a git pull?
  • Unable to pull from git on a Ubuntu Server inside of Virtualbox
  • TeamCity and pending Git merge branch commit keeps build with failed tests
  • git show only tagger and date for tag
  • What is the right way to make a branch the new master of a Git repo?
  • 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?

  • Getting error when trying to generate a migration file
  • Git (Sourcetree) branching and merging - not sure what I did
  • Non-Terminating Process Git Bash (C#)
  • How do I keep GIT repositories inside Dropbox?
  • How do you keep secrets.yml secret in rails?
  • Can EGit revert a merge commit?
  • One Solution collect form web for “Convert stash to working change delimited by #ifdef SYM”

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

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

    Done!

    Git Baby is a git and github fan, let's start git clone.