# Reset the current branch to the commit just before the last 12:git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.# This command sets the state of the index to be as it would just# after a merge from that commit:git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully# prepopulated with the commit messages of all the squashed commits:git commit
# Squash last X commits with a Commit message.# Usage: squash X 'COMMIT_MSG'# where X= Number of last commits.# where COMMIT_MSG= New commit msg.function squash() {if [ -z "${1}" -o -z "${2}" ]; thenecho "Usage: \`squash X COMMIT_MSG\`"echo "X= Number of last commits."echo "COMMIT_MSG= New commit msg."return 1fi
git reset --soft HEAD~"$1"git add . && git ci -m "$2" # With 100 emojigit push --force}
git checkout my-featuregit checkout -b my-rebased-featuregit checkout mastergit checkout my-rebased-featuregit rebase mastergit rebase head^x -i// fixup/pick/rewritegit push origin my-rebased-feature -f // force, if my-rebased-feature was ever pushed, otherwise no need for -f flag// make a PR with clean history, delete both my-feature and my-rebased-feature after merge
(MASTER)Fleetwood Mac Fritz║ ║Add Danny Lindsey StevieKirwan Buckingham Nicks║ ╚═══╦══════╝Add Christine ║Perfect Buckingham║ NicksLA1974══════════╝║║Bill <══════ YOU ARE EDITING HEREClinton (CHECKED OUT, CURRENT WORKING DIRECTORY)
$ git fetch upstream$ git checkout omgpull$ git rebase -i upstream/master
< choose squash for all of your commits, except the first one >< Edit the commit message to make sense, and describe all your changes >
$ git push origin omgpull -f