From ad427a34328cb34066c140ded049553387110c44 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 3 Jun 2022 19:50:44 +0200 Subject: [PATCH] Add shel script for git-helpers --- git.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 git.sh diff --git a/git.sh b/git.sh new file mode 100755 index 0000000..80b2108 --- /dev/null +++ b/git.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -x +commit_before_pull="" + +save_commit_before_pull () { + commit_before_pull=$(git reflog | grep "HEAD@{0}" | cut -d" " -f1) + if ! [ -z "$commit_before_pull" ]; then + if grep -qE "^[[:xdigit:]]{6,}$" <<< $commit_before_pull; then + return 0 + fi + fi + commit_before_pull="" + return 1 +} +# save_commit_before_pull + +revert_to_commit_before_pull () { + if ! [ -z "$commit_before_pull" ]; then + if grep -qE "^[[:xdigit:]]{6,}$" <<< $commit_before_pull; then + `git reset --hard "$commit_before_pull"` + if [ $? -eq 0 ]; then + return 0 + fi + fi + fi + return 1 +} +# revert_to_commit_before_pull