Reputation: 23
Here is the scenario: There is a remote feature branch called "new_feature_x" and two developers, John and Max. The "new_feature_x" log looks like this:
5:[Max - updated button color]
4:[John - merge commit from master]
3:[John - updated API call]
2:[Max - fixed button text]
1:[John - first commit for new_feature_x]
Now the feature is done and John wants to clean up the log into a single commit before merge into master. He does this:
git rebase -i -p master
But it shows only commits 4 and 5. He does fixup for those two, but afterward, commits 1,2,3 are still in the log.
Two questions:
1) How do I combine everything into one commit? Why is everything before the merge commit not appearing when I do "git rebase -i -p master"?
2) What is the best strategy/workflow in the future for this scenario? Should John and Max not use merge commits in a feature branch? I remember reading somewhere that a rebase should never be pushed for a remote shared branch. What is the best way to get changes from master and push to remote branch? The goal is that, when the feature is done, it can be merged back into master as a single clean commit.
Upvotes: 0
Views: 134
Reputation: 2498
Regarding your first question.
This is scenario you described. As you see, commit 3 is only one which already exists in master branch. You branch contain only merge commit.
When you do git rebase -i master
, you are applying feature branch commits upon master branch. You will end up with tree as picture below.
Now you can squash commits in your branch to one and merge to master.
2) I prefer rebasing my feature branch on top of master during development or before I prepare pull request. It's everyone's own preference.
Upvotes: 1