Last active
January 25, 2019 02:41
-
-
Save david-pm/9618a0c60f57ae33cb263b91d743d900 to your computer and use it in GitHub Desktop.
bash script that resets and force pushes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# resets HEAD back one commit, recommits with provided message and force pushes to origin | |
commitmsg=$1 | |
# stole function from: .oh-my-zsh/lib/git.zsh | |
function current_git_branch() { | |
local ref | |
ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null) | |
local ret=$? | |
if [[ $ret != 0 ]]; then | |
[[ $ret == 128 ]] && return # no repo | |
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return | |
fi | |
echo ${ref#refs/heads/} | |
} | |
# exit if no commitmsg | |
if [ -z "$commitmsg" ] | |
then | |
echo "\$commitmsg is empty" | |
else | |
echo "\$commitmsg is NOT empty" | |
# output cmds as they run | |
set -x | |
git reset HEAD~1 | |
git add . | |
git commit -m "$commitmsg" | |
git push origin $(current_git_branch) -f | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment