Last active
March 9, 2017 13:57
-
-
Save scottalan/698a13af6e0315c66178227c2ad89975 to your computer and use it in GitHub Desktop.
Git: squash & rebase
This file contains hidden or 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
# @arg int: The number of commits you want to squash. | |
function squash() { | |
num=${1}; | |
if [ ! num ]; then | |
echo "Integer required"; | |
return 0; | |
fi | |
git reset --soft HEAD~${num}; | |
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"; | |
} | |
# @arg string: The branch you are applying your changes "on top of". | |
function rebase() { | |
rebase_on=${1}; | |
status=`git status --porcelain` | |
if [ -z ${status} ]; then | |
branch=$(git symbolic-ref --short -q HEAD) | |
git checkout ${rebase_on} | |
git pull | |
git checkout ${branch} | |
git rebase ${rebase_on} | |
else | |
echo "Commit your changes: ${status}" | |
return 0; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great functions, however please change the name of the variable 'status' in the rebase function to avoid an error with zsh.