notes/.config/bgit/bgit_revert

31 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
function b_revert() {
read -e -r -p "${txtblue} would you like to revert back to a previous commit?: ${txtyellow}" revert
tput bold & tput setaf 7
if [[ $revert == "y" || $revert == "yes" ]] ; then
read -e -r -p "${txtblue} how many previous commits would you like to see?: ${txtyellow}" numcommits
if [[ $numcommits == "" ]]; then
numcommits=6
fi
commitarray=($(git log -$numcommits | grep commit | sed 's/commit//g'))
verbosecommits=$(git shortlog -$numcommits --reverse | sed 1d);
for ((i = 0; i < numcommits; i++)) do
j=$(echo ${i} + 1 | bc)
nextcommit=$(echo "${verbosecommits}" | head -n $j | tail -n 1)
echo -e " ${txtblue}${i}) ${txtyellow}${commitarray[$i]}${txtblue}${nextcommit}${txtblue}"
done
read -e -r -p "${txtblue} choose commit to revert back to: ${txtyellow}" version
echo "${txtblue} reverting back to version: ${txtyellow}${commitarray[$version]}${txtwhite}"
git reset --hard ${commitarray[$version]}
for ((i = 0; i < numrepos; i++)) ; do
git push --force ${remotearray[i]} > /dev/null 2>&1 ;
done
exit 0
else
echo -e "${txtblue} no revisions to git branch have been made.${txtwhite}"
fi
}