I'm new to git (and enjoying it a lot!). While developing in a new branch, I kept committing the various development 'states' of my application. Now I have to check it in for review but didn't want everything to go in different commits (different comments and ids).
How can I do a push of all changes as if it was the first time?
Merge commits are unique against other commits in the fact that they have two parent commits.
So, instead of merging you first execute the following while on branch-b, git rebase master . This creates new commits that are copies of the old commits, i.e., the same change-set, author information and message, but new committer information and parent history.
Failure to this, cherry-picking can cause duplicate commits and users are encouraged to use git merge in scenarios where it is risky. PS: The branch you cherry-pick from should be deleted, cherry-pick the commits into two or more different branches then delete the faulty branch to avoid code duplication.
git rebase -i HEAD~5
allows you to interactively select which of the 5 last commits to join into one; off the top of my head it opens the editor with something like this
pick xxxx commit1 pick xxxx commit2 pick xxxx commit3 pick xxxx commit4 pick xxxx commit5
you change this into
pick xxxx commit1 squash xxxx commit2 squash xxxx commit3 squash xxxx commit4 pick xxxx commit5
which results in two commits being left: first one that has combined commits 1 - 4, and commit 5 (the newest one) which is left alone
I think it's a good idea to keep your "micro commits". You can do a diff from the last commit before your feature to the current HEAD to see the entire diff which you can send for review.
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