From a5c7caca18642292c887e12bdb79eecf7a9b9506 Mon Sep 17 00:00:00 2001 From: kevin zhuang Date: Fri, 10 Apr 2020 17:20:13 +1000 Subject: [PATCH] allow reset commit --- scripts/freset | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/freset b/scripts/freset index 91e63d2..f45b5c6 100755 --- a/scripts/freset +++ b/scripts/freset @@ -22,13 +22,20 @@ function usage() { } search_commits="" +reset_option="--mixed" -while getopts ":hc" opt +while getopts ":hcSH" opt do case "$opt" in c) search_commits="1" ;; + S) + reset_option="--soft" + ;; + H) + reset_option="--hard" + ;; h) usage exit 0 @@ -44,7 +51,10 @@ done if [[ -n "${search_commits}" ]]; then selected_commites=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" log --oneline --color=always --decorate=short | \ fzf --header='select which commit to reset' --preview "echo {} | awk '{print \$1}' | \ - xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __") + xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __" | \ + awk '{print $1}') + [[ -z "${selected_commites}" ]] && exit 0 + /usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset "${selected_commites}" "${reset_option}" else selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --name-status --cached | \ awk '{print "\033[32m" $1 " " $2}' | fzf --header='select files to unstage' --multi --preview "echo {} | awk '{print \$2}' | \