0

If I have a feature branch I've been working on and want to clean it up, like squashing all the commits into 1 commit, would I:

  1. rebase against the first commit of that feature branch git rebase <COMMIT>; or

  2. against master? git rebase -i master

I am not sure the use case and differences of both.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
herkypam
  • 75
  • 2
  • 11
  • Take a look at `git rebase --onto` https://stackoverflow.com/questions/33942588/difference-between-rebase-master-and-rebase-onto-master-from-a-branch-deri Other method would be to checkout master, merge in your branch, and then squash commits. – EncryptedWatermelon Jul 08 '19 at 20:47

1 Answers1

1

In general, you could use any of the following:

git rebase -i the-other-branch
# pick the first revision, squash the others. That will work

You could also do what I do:

git merge -m "Getting updates from main branch" master # do not worry, we will get rid of this revision next
git reset --soft master # now all differences between your branch and master (in other words, all changes related to your feature branch) will be in index
git commit -m "My feature"

Hope it helps.

eftshift0
  • 26,375
  • 3
  • 36
  • 60