Question:
I am working on a feature branch.
- Made several commits. Squashed commits.
- Pushed changes to remote branch. Got conflicts.
- Merged changes from master, resolved conflicts on feature branch.
git fetch origin master
git merge FETCH_HEAD
- Resolved conflicts manually.
git commit
git push
- I made one more commit.
So, current commit history looks like this.
From current to old:
- commit 3
- commit M yyy (Merged)
- commit 2
How do I squash above 3 commits into 1 before I merge my feature branch to master?
Answer:
You can rebase -i
starting with commit 2
‘s parent (that is, the commit on master
that you branched from. You’ll likely have to re-resolve conflicts when you get to the merge commit.
So if your history looks like
1 2 3 4 5 6 7 8 |
* D commit 3 (HEAD) * M merge /| | * C commit 2 * | B commit on master |/ * A (master) |
Start with git rebase -i A
. You’ll see a list of commits including both master
and your_branch
, but not the merge commit. pick
the first one (B
or C
, depending on timing) and squash
the rest.