Alias: `git pop last`, for` git stash pop [last stroke on the list] `

Is it possible? I need a simpler command git stash pop stash@{13}, where it stash@{13}will be simple last, which means "last cache in the list" or "oldest cache".

I know that I can create an alias git popfor git stash pop(which I could use as git pop stash@{13}), but I would like to do something simpler than git pop last. Do I need to write my own script or is there a way to do this with just git or an alias? I use Windows, but sometimes Linux.

+4
source share
1 answer

Changing @torek's prompts will give you a message saying what you want:

git reflog stash -- 2> /dev/null | tail -n 1 | cut -d ' ' -f 2 | cut -d ':' -f 1

--ensures that you are looking for a version, not a path. 2> /dev/nullsuppresses errors if there are no delays.

An alternative that avoids the use of cut(again suggested by @torek) is:

git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1

Thus, you can set your alias as follows:

git config alias.pop-last "! git stash pop $(git reflog stash -- 2> /dev/null | tail -n 1 | cut -d ' ' -f 2 | cut -d ':' -f 1)"

Or:

git config alias.pop-last "! git stash pop $(git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1)"

Any of these commands will give you a good mistake No stash found.if it is not found.

I tested and it works at the Git Bash prompt on Windows. (It should also work on Linux.)

+5
source

Source: https://habr.com/ru/post/1652656/


All Articles