How
You need to get the merge base of your branch
git merge-base master your-branch
# 566f8438e0cd0e331ceb49a9cb0920143dfb065c
Then you can rebase to it
git rebase -i 566f8438e0cd0e331ceb49a9cb0920143dfb065c
# then squash/pick/do commit messages
or just do a soft-reset and commit everything
git reset --soft 566f8438e0cd0e331ceb49a9cb0920143dfb065c
git add .
git commit -m "The only commit"
Automate
If you do this often you can automate it by putting these in your .bashrc
using.
g-rebase-branch() {
git branch --show-current | xargs git merge-base master | xargs git rebase -i
}
g-one-commit() {
local last_commit_message=`git show -s --format=%s`
git branch --show-current | xargs git merge-base master | xargs git reset --soft
git add -A
git commit -m "$last_commit_message"
git commit --amend
}
and then do these directly in the terminal.
g-one-commit
but if you're merging against a different branch than master then you can replace master
with "$1"
to do this
g-one-commit staging
git rebase -i 58333012713fc168bd70ad00d191b3bdc601fa2d
wich will do an interactive rebase where the commitnumber is the last commit that stays unchangedgit rebase -i --root master