Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge commits [duplicate]

Tags:

git

git-merge

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?

like image 516
DiogoNeves Avatar asked Feb 08 '11 17:02

DiogoNeves


People also ask

Are merge commits special?

Merge commits are unique against other commits in the fact that they have two parent commits.

What happens to commits after merge?

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.

Does cherry pick duplicate commits?

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.


2 Answers

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

like image 196
stijn Avatar answered Sep 30 '22 07:09

stijn


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.

like image 21
Noufal Ibrahim Avatar answered Sep 30 '22 05:09

Noufal Ibrahim