0

Basically, I'm trying to write a script that ensures that a certain commit has been merged.

When i try to execute the command git branch --contains 0871b8479e6332ee3bd7a1ea9ea5b53795c3b3c5 in my terminal, I face the following error:

no such commit 0871b8479e6332ee3bd7a1ea9ea5b53795c3b3c5

This commit is the hash of one of the commits of a branch that has now been merged (and the branch was subsequently deleted). I need a way to confirm that this commit has been merged into the develop branch from shell script/github cli.

PS: I've tried using other branch based approached like git branch -a --merged, but I'm still not able to confirm that either my branch or my commit have been merged.

  • Start with something like gitk to find the place where the branch was merged. You may find that the branch was squashed/rebased before merging and the specific incarnation of the commit you are thinking of really doesn't exist any more. – Mad Physicist Apr 11 '22 at 13:18
  • Put it another way, we make commits to modify something. It's not the commit that's important but the modification it introduces. If you can, search for that in the code or whatever else you are maintaining in version control. It's both easier and more meaningful. – Mad Physicist Apr 11 '22 at 13:19
  • The error message tells you that the given commit is *definitely not* in the repository. Because the commit itself is absent, you cannot get anything more from Git that has anything to do with that commit itself (unless you put that commit *into* that repository somewhere, after which it will be only on whatever branches *you* put it into). But, as @MadPhysicist says, perhaps there's another commit that's "just as good or better" than *that* commit. – torek Apr 12 '22 at 11:19
  • How did you determine that commit hash? – knittl Oct 19 '22 at 20:31

1 Answers1

0

How did you merge? "no such commit" makes me believe you "squash-merged" that branch. In that case you are out of luck. The commit is gone and you have no way to know into which commit it was squashed.

If you performed a "real" merge (creating a merge-commit with 2+ parents) or a fast-forward merge, then git branch --contains commit_id is the correct way to approach this.

Make sure to have fetched the remote history before running the command.

knittl
  • 246,190
  • 53
  • 318
  • 364