Skip to content

Instantly share code, notes, and snippets.

@cameronehrlich
Forked from burin/gist:ab156df44fd313bb1b0a
Last active October 26, 2017 20:03
Show Gist options
  • Save cameronehrlich/88f55996ecaa95173df18d91bcfc1a3a to your computer and use it in GitHub Desktop.
Save cameronehrlich/88f55996ecaa95173df18d91bcfc1a3a to your computer and use it in GitHub Desktop.
Squashing your commits into one commit without using interactive rebase.
git fetch -ap # get in sync w/ server
BRANCH_NAME=$(git symbolic-ref --short -q HEAD)
git checkout $BRANCH_NAME # switch to the appropriate branch
git reset --hard origin/$BRANCH_NAME # get my branch to be exactly the same as what's on the server
MERGE_BASE=$(git merge-base origin/$BRANCH_NAME origin/master) # get the commit where your branch originates
git reset --mixed $MERGE_BASE # reset to the point where your branch originates, but put your changes like you just made them
git add . # stage your changes for a new commit
# echo "Enter your commit message, followed by [ENTER]:"
# read MESSAGE
git commit -m 'Commit message here' # commit your new commit
git push origin $BRANCH_NAME -f # force push it up to the server. you are rewriting history (check that everything looks ok before doing this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment