From 512732fcb35912d8d4256c8d70d6d443304e2128 Mon Sep 17 00:00:00 2001 From: phone Date: Sat, 30 Sep 2023 07:20:31 +0300 Subject: [PATCH] bash : make gr accept head count. --- document/linux/config/bash/module/git.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/document/linux/config/bash/module/git.sh b/document/linux/config/bash/module/git.sh index cc294df..42d10ce 100644 --- a/document/linux/config/bash/module/git.sh +++ b/document/linux/config/bash/module/git.sh @@ -7,7 +7,6 @@ alias gst="git stash" alias gd="git diff" alias gc="git commit -m" alias gch="git checkout" -alias gr="git rebase -i" alias gb="git branch" alias gco="git checkout" alias gf="git fetch" @@ -28,3 +27,21 @@ ga() git diff $@ git add $@ } + +# rebase by X commits or from root. +gr() +{ + local base="${1}" + + # rebase last 2 commits by default. + if [[ "${base}" = "" ]]; then + base="2" + fi + + # if 0, rebase from root. else from specified base. + if [[ "${base}" = "0" ]]; then + git rebase -i --root + else + git rebase -i HEAD~${base} + fi +}