Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if a given git hash exists on a given branch?

Tags:

git

Background: I use an automated build system which takes a git hash as input, as well as the name of the branch on which that hash exists, and builds it. However, the build system uses the hash alone to check out the code and build it -- it simply stores the branch name, as given, in the build DB metadata.

I'm worried about developers accidentally providing the wrong branch name when they kick off a build, causing confusion when people are looking through the build history.

So how can I confirm, before passing along the hash and branch name to the build system, that the given hash does in fact come from the given branch?

like image 558
Pinko Avatar asked Mar 14 '10 22:03

Pinko


People also ask

How do you know if a commit is present in a branch?

Search the branch (say, feature ) with exact matching. You can also search in both local and remote branches (use -a ) or only in remote branches (use -r ). The grep here could also result in false positives if there are other branches containing the commit whose names also contain <branch-name> as a substring.

How do I know if hash is committed?

If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .

How do I checkout a hash in git?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.


1 Answers

You can ask git branch directly which branches contain the commit in question:

% git branch -a --contains 4f08c85ad * master   remotes/origin/bug_872   remotes/origin/bug_898   remotes/origin/master 
like image 166
Dustin Avatar answered Sep 19 '22 02:09

Dustin