Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git : Merge multiple commits from one branch into another

I have following use case.

  1. I have a mainline branch.
  2. Created new branch(dev) from mainline.
  3. Did multiple commits(around 20) into dev branch and pushed into dev(remote) branch as well.

Now I want to merge all these 20 commits into single commit and move this to mainline. How exactly I can do this?

Thanks in Advance,
Shantanu

like image 466
shantanu Avatar asked Dec 17 '15 07:12

shantanu


People also ask

How do you squash commits on a new branch?

Git squash with a commit id The last command opens the interactive Git rebase tool which lists all of the commits in the branch. You must type the word pick next to the commit you want all others to be squashed into. Then type 'squash', or just the letter 's', next to each commit to squash.

How can you move from 4 commits to one commit?

You can use git merge --squash to squash the commits into a single one while merging into the branch. All the commits in original-branch will be merged into a single one, and applied to the target-branch .


1 Answers

That sounds like a git merge --squash

git checkout mainline
git merge --squash dev
git commit

Note that, as commented here, it is best to merge mainline in dev first and solve any conflict there, before merging back dev in mainline.

like image 129
VonC Avatar answered Sep 28 '22 10:09

VonC