Created
October 15, 2014 05:29
-
-
Save khacanh/9863f575d605e543d2d7 to your computer and use it in GitHub Desktop.
Git god!
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
# Original http://rebaseandsqua.sh/ | |
#!/bin/sh | |
set -e | |
# Get the current branch name. | |
branch=`git rev-parse --abbrev-ref HEAD` | |
# Determine the commit at which the current branch diverged. | |
ancestor=`git merge-base master HEAD` | |
# Stash any uncommited, changed files. | |
git stash --all | |
# Revert the branch back to the ancestor SHA. | |
git reset --hard $ancestor | |
# Squash all commits from ancestor to previous SHA. | |
git merge --squash HEAD@{1} | |
# Perform the commit, prompting for the message. | |
git commit | |
# Fetch the latest changes from the upstream branch. | |
git fetch origin master | |
# Rebase the current single commit onto the latest. | |
git rebase master | |
# Restore previous uncommited changes, if any. | |
git stash pop || true | |
printf "\nDone! Push with 'git push -f origin %s'\n" "$branch" | |
exit 0 # High five! Everything worked. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment