How to execute alias git checkout && git apply cache

So, I have two branches master and formtest

I have [alias] "git switch", which allows me to lock any work in progress and check out another branch.

"git switch"

switch = !git stash && git checkout 

Now I want to create [alias]

"git switchback"

 switchback = ??? 

at startup, I want him to say

switch to this formtest branch

and then run the stash apply application

to unblock the last WIP and bring it back before I first started git switch

+4
source share
2 answers

To return to the branch you were working on before

 git checkout - && git stash apply 

- will work similarly - in cd - for example. go back to the last branch (location) that you used.


But beware that this will checkout wrong branch if you encounter a checkout with another branch between them.

0
source
 git checkout $(git log --format=%B -n 1 stash@ {0} | grep -oP '(?<=^WIP on )[^(:][^:]*' || git rev-parse stash@ {0}^) 

This will analyze the last commit message, which contains the name of the branch in which it was executed. If there was no branch (a separate head), it will check the parent commit of the cache.

0
source

All Articles