Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:03:08+00:00 2026-05-14T09:03:08+00:00

Is there a way to find out what branch a commit comes from given

  • 0

Is there a way to find out what branch a commit comes from given its SHA-1 hash value?

Bonus points if you can tell me how to accomplish this using Ruby Grit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:03:09+00:00Added an answer on May 14, 2026 at 9:03 am

    While Dav is correct that the information isn’t directly stored, that doesn’t mean you can’t ever find out. Here are a few things you can do.

    Find branches the commit is on

    git branch -a --contains <commit>
    

    This will tell you all branches which have the given commit in their history. Obviously this is less useful if the commit’s already been merged.

    Search the reflogs

    If you are working in the repository in which the commit was made, you can search the reflogs for the line for that commit. Reflogs older than 90 days are pruned by git-gc, so if the commit’s too old, you won’t find it. That said, you can do this:

    git reflog show --all | grep a871742
    

    to find commit a871742. Note that you MUST use the abbreviatd 7 first digits of the commit. The output should be something like this:

    a871742 refs/heads/completion@{0}: commit (amend): mpc-completion: total rewrite
    

    indicating that the commit was made on the branch “completion”. The default output shows abbreviated commit hashes, so be sure not to search for the full hash or you won’t find anything.

    git reflog show is actually just an alias for git log -g --abbrev-commit --pretty=oneline, so if you want to fiddle with the output format to make different things available to grep for, that’s your starting point!

    If you’re not working in the repository where the commit was made, the best you can do in this case is examine the reflogs and find when the commit was first introduced to your repository; with any luck, you fetched the branch it was committed to. This is a bit more complex, because you can’t walk both the commit tree and reflogs simultaneously. You’d want to parse the reflog output, examining each hash to see if it contains the desired commit or not.

    Find a subsequent merge commit

    This is workflow-dependent, but with good workflows, commits are made on development branches which are then merged in. You could do this:

    git log --merges <commit>..
    

    to see merge commits that have the given commit as an ancestor. (If the commit was only merged once, the first one should be the merge you’re after; otherwise you’ll have to examine a few, I suppose.) The merge commit message should contain the branch name that was merged.

    If you want to be able to count on doing this, you may want to use the --no-ff option to git merge to force merge commit creation even in the fast-forward case. (Don’t get too eager, though. That could become obfuscating if overused.) VonC’s answer to a related question helpfully elaborates on this topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ISO-8859-1 does not support the em-dash character. You're actually using… May 14, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer Yes, finalizers are allowed to call other methods. Hell, you… May 14, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer Make sure your bean is in a bean archive -… May 14, 2026 at 6:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.