I am working on a feature using git and I have the following steps completed so far.
feature1
based on master
test
based on feature1
.test
. feature1
branch. test
branch to feature1
test
branchHere is git log --oneline -n 5
output
de5d701 Merge branch 'test' into 'feature1' (amended)
a668f93 'feature1' commit3
ded7c00 'feature1' commit2
8731807 Initial 'feature1' commit
ff2f539 latest 'master' commit
I want to squash everything which comes after ff2f539 latest 'master' commit
before merging to master
. I tried to perform
git rebase --interactive ff2f539
but the latest commit is not listed in the editor:
pick 8731807 Initial 'feature1' commit
pick ded7c00 'feature1' commit2
pick a668f93 'feature1' commit3
# Rebase ff2f539..de5d701 onto ff2f539
#
# Commands:
...
# Note that empty commits are commented out
I can not understand why the latest commit which is produced by the merging of test
branch to feature1
branch is skipped.
Saving and exiting the editor with the following content:
pick 8731807 Initial 'feature1' commit
squash ded7c00 'feature1' commit2
squash a668f93 'feature1' commit3
# Rebase ff2f539..de5d701 onto ff2f539
#
# Commands:
...
# Note that empty commits are commented out
produces new commit which does not provide the changes from the last commit
de5d701 Merge branch 'test' into feature1(amended)
They are lost. Any help how to squash all those commits into one single commit before merging to master ?
Git does not show merge commits in the "interactive" list by design. It instead includes all commits that were brought into the branch by that merge. You can use -p
(--preserve-merges
) option to change that behavior, but it is not recommended in interactive mode, because the result may be not that obvious (see http://git-scm.com/docs/git-rebase#_bugs).
But there is a simple solution without rebasing:
# make sure your working copy is clean, do git stash if needed
git checkout feature1
git reset --soft ff2f539
git commit -m "..."
This will produce one commit including all changes after ff2f539.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With