Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive rebase after merging/other commits interleaving mine

Tags:

People also ask

Can you rebase after a merge commit?

The good way is to use rebase, but once we rebase this branch onto master, all merge commits are gone. Following GIF shows how such a rebase operation omits all merge commits: The new option --rebase-merges prevents this problem. With this option, the rebase command successfully includes all merge commits.

Why you should rebase instead of merge?

Reading the official Git manual it states that rebase “reapplies commits on top of another base branch” , whereas merge “joins two or more development histories together” . In other words, the key difference between merge and rebase is that while merge preserves history as it happened, rebase rewrites it .


My typical git workflow is to make a feature branch off our master branch, make small commits, while periodically merging from master along the way to keep up.

I then open a pull request on github and when it's accepted I'll delete the branch. I'd like to interactively rebase more but when I do I'll encounter merge commits and other people's commits interleaved with my own. I'm not sure how/if I can squash those commits or group/squash mine alone?

For instance, my git log for my branch might look like this when it comes time to rebase:

merge commit
someone else's commit
one of my commits
another one of my commits
another merge commit
another person's commit
one of my commits, the first one after branching

I'm having trouble with what's possible and what's not when doing an interactive rebase and squashing and reordering commits. Given the above workflow, what would you recommend?