Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging changesets in git for a code review

Tags:

git

diff

patch

I have around 50 relevant commits on my local git repo, of this list I want to show in a code review only my commits.
But they are mixed with other people commits, and some of my commits are corrections to others, so I don't want to go commit by commit because I would step twice in the same code, for the original and for the correction.
The best thing for me would be to do something like this:
git combine-commits 4 9 20 35 67 90 102 > myfile.diff
In such a way that 67 fixes an error on 20 and the diff shows the corrected version.

Is there any way of geting this?

like image 309
Arkaitz Jimenez Avatar asked Jul 02 '10 09:07

Arkaitz Jimenez


People also ask

How do you merge your code in git?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

What is the purpose of merging in git?

Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.

What is a merge request in git?

A merge request (MR) is a request from someone to merge in code from one branch to another. You can create a MR from Assembla by clicking on New Merge Request, which is in almost all of git sub-tabs.


1 Answers

One way would be to create a new working branch based at a point before the oldest commit you want to include, git cherry-pickthe commits you want to review onto that branch and extract the diff from the new branch (just git diff start-ref when you have your temporary branch checked out). Once you've finished the review you can throw away the temporary branch. One thing to watch out for is that the sha refs on your temporary branch will be different to the ones you started with, but I don't expect that will be a problem.

like image 59
Andrew Walker Avatar answered Nov 02 '22 13:11

Andrew Walker