Ritesh Mahato
Ritesh Mahato

Reputation: 631

How to merge multiple code review links to a single link in git/gerrit?

I have had sudden changes to make after I committed my code in git. Now I have 3 commits and three code review links for these. Is there a way I can merge the three links to a single code review link where all the changes are displayed?

Upvotes: 0

Views: 888

Answers (2)

Murali
Murali

Reputation: 46

I don't think there's a way to merge your three code review links into a single Gerrit code review link. But there's definitely a way to merge your multiple commits into a single commit. This can be done using a combination of rebase and squash.

First, rebase your HEAD with how many commits you'd like to merge in. In this is case it is 3.

git rebase -i HEAD~3

This would bring you into your editor with something like this:

pick 62cf05f LAZY Fixing integration build errors, go 2  
pick eb2fc19 Lazy service call implementation  
pick 2dea6da List of available bank from

Edit this file to look something like this:

pick 62cf05f LAZY Fixing integration build errors, go 2
squash eb2fc19 Lazy service call implementation
squash 2dea6da List of available bank from

Then Write/Quit. You'd now be prompted with an editor again to enter a commit message. Enter whatever you'd like to, there and then Write/Quit.

Boom. You now have a new commit ID, on top of which you can generate a new code review link.

Note: You may encounter merge conflicts while rebasing, if auto-merge fails. In that case, resolve merge conflicts manually, add/rm those files, and do git rebase --continue.

Upvotes: 1

mrutyunjay
mrutyunjay

Reputation: 8310

Try :

 git rebase -i HEAD~N
 #N is number of changes from HEAD. Here in your case it is 3

 git rebase -i HEAD~3

Once you run above command , you will see one prompt with the options listed. Use squash to combine your commits into one.

Upvotes: 1

Related Questions