diff --git a/nvim/.config/nvim/after/ftplugin/git.vim b/nvim/.config/nvim/after/ftplugin/git.vim index ea4a95a..d7613ed 100644 --- a/nvim/.config/nvim/after/ftplugin/git.vim +++ b/nvim/.config/nvim/after/ftplugin/git.vim @@ -12,3 +12,4 @@ nnoremap gL :call git#git_branch_log_pretty() nnoremap gp :call git#git_cherry_pick() xnoremap gP :call git#git_cherry_pick_range() nnoremap gr :call git#git_rebase_branch() +nnoremap gR :call git#git_reflog_restore() diff --git a/nvim/.config/nvim/after/plugin/fugitive.vim b/nvim/.config/nvim/after/plugin/fugitive.vim index af4c8bb..2610a42 100644 --- a/nvim/.config/nvim/after/plugin/fugitive.vim +++ b/nvim/.config/nvim/after/plugin/fugitive.vim @@ -25,6 +25,7 @@ nnoremap g- :Git stash:e nnoremap g+ :Git stash pop:e nnoremap gs :Git nnoremap gS :Git stash -- % +nnoremap gt :Git reflog nnoremap gw :Gwrite nnoremap G :Git diff --git a/nvim/.config/nvim/autoload/git.vim b/nvim/.config/nvim/autoload/git.vim index f23e98c..4409bcf 100644 --- a/nvim/.config/nvim/autoload/git.vim +++ b/nvim/.config/nvim/autoload/git.vim @@ -181,6 +181,27 @@ function! git#git_rebase_branch() abort silent execute "bw" endfunction +" Git reflog should be run first before invoking this +function! git#git_reflog_restore() abort + let line = trim(getline('.')) + " A line in git reflog is of the form below + " f6a8c7ed4 HEAD@{73}: rebase (pick): gst-rtmp: Add mux queues to stats gathering + let sl1 = split(line, ":") + " sl1[0] will give f6a8c7ed4 HEAD@{73} for above example + let sl2 = split(sl1[0], " ") + " sl2[0] will have f6a8c7ed4 and sl2[1] will have HEAD@{73} + echom "Command executed will be: Git reset --hard " . sl2[1] + call inputsave() + let restore = input('Restore to: ' . line . '. Enter y to proceed: ') + call inputrestore() + let to_restore = match(restore, 'y') + if (to_restore == 0) + execute "Git reset --hard " . sl2[1] + else + echom "Not restoring to " . line + endif +endfunction + " Figures out whether default branch is main or master and runs git rebase. function! git#git_rebase_origin() abort let default = split(trim(system('git symbolic-ref refs/remotes/origin/HEAD')), '/')