0

I branched off of master to build a feature for our website, the branch now has maybe 1,000 commits now, and I don't want to merge that into the master. I would like to take the HEAD of the branch and basically remove all of the other commits.

I tried doing a rebase but that didn't seem to work, as it still shows the 1k(ish) commits.

git rebase -i dev-dashboard

I would then like to squash ALL commits and make the HEAD the only commit, then merge that into the master. How can this be done?

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • This seems like a duplicate of http://stackoverflow.com/a/5201642/1256452 - but consider whether you really want that, since merging a single squashed commit, vs merging the 1000 commits, is exactly the same as far as git is concerned. The only real difference is whether the resulting merge has 1000 commits on the incoming branch, or just the one final one. (It's the same to merge because merge just looks at the start-and-end, ignoring all the intervening commits.) – torek Jul 18 '15 at 01:30
  • So, if master has 5 commits and mine has 1000, when it is merged master will now show 6 commits instead of 1006? – Get Off My Lawn Jul 18 '15 at 01:32
  • 1
    Commits aren't necessarily linear like that. If you squash first then merge, `master` will have *7* commits, 6 on the "straight line" A-B-C-D-E-M and one on the "branch line" A - (down) F - (up) M (not counting A again, since it's "up"). If you don't squash, you'd have the same 6, but 1000 on the "down" line. (I can't really draw these as a graph in a comment...) Note that `git log` follows both branches "simultaneously" by default; `--first-parent` tells it to ignore the "incoming" branches. – torek Jul 18 '15 at 01:35
  • You could delete the branch afterwards if you don't want to see them all... – rholmes Jul 18 '15 at 01:43

1 Answers1

1

It seems like this should be easier, but this could get you started:

git checkout topic
git reset master
git checkout master
git add .
git commit -m 'Over 1,000 fakie rebase squash!'
git branch -d topic

Inspired by this

Git squash all commits in branch without conflicting

Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407