1

I want to squash some local commits using rebase -i but I have pulled in and merged other peoples changes in between my local commits. Is it still possible to use this command?

haymansfield
  • 4,700
  • 4
  • 32
  • 50

2 Answers2

1

I believe it got support for rebasing merges some time ago, so try it.

But even if it didn't, you can always create new branch from after changes you merged in and use git cherry-pick to apply your changes there and than tweak them with rebase.

For the future, use git pull --rebase or git fetch followed by git rebase (-i) instead of plain pull to your private working branches, so your changes end up rebased on top of what you pull instead of mixed in with merges.

Jan Hudec
  • 65,662
  • 12
  • 114
  • 158
1

From the git rebase man page:

-p, --preserve-merges Instead of ignoring merges, try to recreate them.

It also includes the warning:

This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing.

The warning refers to the discussion here. Issuing git rebase -i -p can lead to unexpected results when reordering commits, so I'd recommend becoming familiar with the many ways to undo a bad rebase. Most importantly, remember the golden rule of rebasing: Never rebase history you've shared with others.

Community
  • 1
  • 1
Christopher
  • 36,834
  • 9
  • 72
  • 91