Praveen
Praveen

Reputation: 439

Git rebase vs recreating branch and applying changes

I have to rebase and then, squash and merge my changes. But, the rebasing is taking too much time and effort. So, what if, instead of rebasing, I delete the feature branch, create a fresh one from master and then, apply my changes at the top and push in a single commit?

  1. Will it be any different than rebasing?
  2. Will the git(hub) review comments be preserved?

Upvotes: 2

Views: 372

Answers (1)

Zaz
Zaz

Reputation: 48729

From a technical standpoint, the end result is the same. Rebase is just a smart tool to do exactly what you describe.

I've resorted to manual editing a few times in the past, but generally it pays off to get proficient at using interactive rebase using Vim or Emacs.

rebase -i seems arcane at first, especially as the default text editor is often Vim; however, the two go very well together: if you want to reorder commits, you just hit j until you get to the commit you want to move dd to delete the line then j again (or k to go up) until you find the place you want to put it, then p to paste it.

Or, say you want to squash a three commits into one, use jjj (or 3j) to get to the line you want, then use cw (change word) s ("squash" (see instructions at top of text file)) Esc j .

Where Esc leaves insert mode and returns to "normal" mode and . repeats the last command.

Upvotes: 1

Related Questions