1

Ok, I have branch feature/12, it's more or less done, so I branch off it and start working on feature/13, which depends on feature/12.

Code review happens and a few small changes are made to feature/12. So I apply those changes, then squash against master into a single feature commit, as is protocol in the company (git rebase -i master).

Now back to feature/13, how do I consolidate feature/13's history so there are no history conflicts against feature/12 and master? Do I simply git rebasefeature/12` and fix any conflicts?

o_o_o--
  • 905
  • 8
  • 17

2 Answers2

3

Yes, just rebase against master.

Rebase will attempt to apply the unsquashed commits on top of the squashed one, and likely see conflicts (though independent or last ones will be recognized as already applied and automatically skipped). You can:

  • simply fix the conflict as usual, which should result in no staged changes,
  • recognize the old commit and git rebase --skip when it comes up, or
  • since you are using interactive rebase, delete the old commits' pick lines from the git-rebase-todo file.

If you're feeling extremely cautious, and you'd like to make sure the rebase operation didn't accidentally add or remove any changes that you have on feature/13, you can diff the diffs from the pre-rebase version and now by using a command like this immediately after finishing the rebase operation:

diff -u <(git diff master...feature/13@{1}) <(git diff master...feature/13)

This does not give perfectly clean output — it will report differences in context lines, and I don't know of a better way — but will definitely show you any changes lost (or gained) due to rebase.

Community
  • 1
  • 1
Kevin Reid
  • 21,218
  • 9
  • 61
  • 82
1

Do I simply git rebase feature/12 and fix any conflicts?

That'll do it, but notice that the additional changes in feature/12 that got merged are also in master now, too, and any conflicts have already been resolved there. It's also just plain cleaner to base your work on the production version of any dependencies. If it later turns out you need to rebase again off new work in feature/12, you'd have had to do that anyway.

jthill
  • 42,819
  • 4
  • 65
  • 113