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?

4
  • This seems like a duplicate of 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
    Commented Jul 18, 2015 at 1:30
  • So, if master has 5 commits and mine has 1000, when it is merged master will now show 6 commits instead of 1006? Commented Jul 18, 2015 at 1: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
    Commented Jul 18, 2015 at 1:35
  • You could delete the branch afterwards if you don't want to see them all...
    – rholmes
    Commented Jul 18, 2015 at 1:43

1 Answer 1

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

3
  • Note that this throws away all changes to master that occurred after the topic branch was created. Not sure if that's what OP wants. Commented Jul 18, 2015 at 5:55
  • @RaymondChen you are quite welcome to present your own answer
    – Zombo
    Commented Jul 18, 2015 at 6:00
  • Already answered by the answer linked to by first comment. git merge --squash. Commented Jul 18, 2015 at 6:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.