I have multiple commits in one branch. When I push these commits for code review, our code review tool creates one review for each commit.
To avoid this I want to merge multiple commits to a single commit. At the same time I don't want to lose the history of commits. Is it possible to create a new branch only for review and combine all the commits in my master branch to a single commit in my review branch? How do I do this?
I dont know your review tool, but this may work
git checkout review
git merge --squash master
http://www.kernel.org/pub/software/scm/git/docs/git-merge.html
You do not want to do it. The actual history in the sense of how you did the commit is worthless. The suitably-sized-for-review chunks are interesting, so just rebase -i
your working branch to combine the commits to manageably-sized and most importantly logical chunks, post them to review and forget about the original history.
That said, to combine the commits, you can use:
git merge --squash
Git will not throw away the history. It does not actually do that in rebase
either, but in that case the previous version of the history only remains accessible through the "reflog" and only if you have expiration for reflogs (IIRC it's 90 days by default), it will eventually become inaccessible and git gc
will throw it away. But with the squash, the original branch simply remains there and you can still name the revision from reflog.
However the reviewed history will be merged to the central master by the review tool and nobody will ever see your original history. You can keep it around, but it will not be related to the official one and nobody will ever look at it anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With