git compare two branches which contains some common commit with different hash
Asked Answered
E

1

6

Context : We are a team of programmer who work on a project with severals branches :

Master, Release, Develop

Sometimes we need to fix a bug on release, and we need to report this fix on develop, to report our bug fix we use : git cherry-pick commit-SHA

With this command the bugfix is well reported on develop but the commit has a different hash

What we need :

Sometimes we need to know the list of commits that has not been reported, to do so, we use the command who compare the two branches and give us the list of commit which exist in release but not in develop : git log develop..origin/release

The ISSUE :

This command compare the hash of commits, but as i said before, when we report our commits, their hash changes, thus, we get some commits as if they were not been reported while they are

I'm lookin for a way to report our bugfix without changing the hash of commits, or a way to list the difference of commits between two branches, not by the hash but based on the message or another thing

Thanks

Expletive answered 6/10, 2018 at 16:39 Comment(4)
cherry-pick is not the right way to apply a commit to two branches. Read this series of articles to learn why cherry-pick is not good and how to do it correctly.Vadim
Commit hashes never change. Two things with different hashes are different commits. It sounds like you are looking for git patch-id, which computes a hash for the diff listing from git show, i.e., a hash ID for a changeset, as opposed to a hash ID for a commit. Two different commits will generate the same patch ID if they make the same changes to the same files, for some definition of "the same".Orcinol
Because this particular concept is fairly useful, Git has additional commands for working with patch IDs: git cherry does this for branch sets, and git rev-list has --cherry-mark for doing this with symmetric difference operations. All of them use the git patch-id code internally to do this, but if they don't do what you need, you can invoke git show <commit> | git patch-id to compute your own patch IDs and use them however you like.Orcinol
With all that said, see @axiac's link for a better way: one should only do this mucking-about with patch IDs if one is stuck in a horrible situation.Orcinol
I
5
git log --cherry-pick develop...origin/release
  • The three dots between the branches ... means that you want to retrieve distinct commits from the two branches
  • From official documentation --cherry-pick option does :

"Omit any commit that introduces the same change as another commit on the “other side” when the set of commits are limited with symmetric difference."

Icbm answered 7/1, 2019 at 21:41 Comment(2)
--left-only, --right-only options can be useful for OP's task tooChaffee
is it possible only commits << that introduce the same change as another commit on the “other side” >> (instead of omitting them)?Penetrate

© 2022 - 2024 — McMap. All rights reserved.