We have a workflow where committed code needs to be reviewed by other devs. In simple cases this can be done with "git diff oldhash newhash > diff.txt" and upload that to our review board.
But is there a way to create a diff over several commits and exclude commits done in between by someone else. For example I want to create diff over mine1 to mine4 but exclude Joe's commit :
mine4
mine3
joe's
mine2
mine1
Any ideas how to do this in command line git or with some other tool?
The commits made by others affect different files than my commits, so in this case it is just about excluding changes made by others.
Okay, maybe it is not true git way, but I would create new branch, removed unneeded commits and compared two branches.
You could achieve this by creating a new branch combined with cherry-pick:
git checkout -b mine_diffs
git cherry-pick mine1
git cherry-pick mine2
git cherry-pick mine3
git cherry-pick mine4
git diff mine1_ mine4_
When you're done, just delete the branch. Note that the sha1 hashes will be different when diffing, which is what mine1_ and mine4_ indicates.
I'm not quite sure what you mean by "over mine1 to mine4". Diffs are always pairwise (except for mid-merge); "git diff mine1 mine4" will give you all the changes between those two trees. Given the above example, you can get four separate patches: mine1->mine2, mine2->joes, joes->mine3, mine3->mine4. If you did mine1->mine2, mine2->mine3, mine3->mine4 you'd still "see" joe's changes.
Perhaps what you want is (as @OleksandrKravchuk suggested) "a diff of what one would have, if one cherry-picked the changes in mine2, mine3, and mine4 into a branch that started from mine1". In that case, you'll have to do just that: create such a branch, pick those changes to apply, and then generate the diff.
You could automate this fairly easily by creating the temporary branch and doing the sequence of "git cherry-pick"s, skipping the commit(s) you want to omit.
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