0

From my master branch, there is a bad commit that was merged in at some point. Is it possible to find out which branch it came from?

Summitch
  • 350
  • 3
  • 12

2 Answers2

0

If you know more or less when and where it happened, this a a neat visualization command:

git log --graph --decorate --oneline --all

If there is a lot of history and have no idea where to begin looking, your question has been previously answered in Finding what branch a commit came from.

Community
  • 1
  • 1
Ed I
  • 7,008
  • 3
  • 41
  • 50
0

TL;DR

Yes and no. Commits carry ancestor history, but they don't actually carry branch information. Such information is calculated rather than stored or passed around as first-class data. You might find git-bisect a better option.

Finding Branches Containing a Commit

You can use git branch --contains <commit> to find branches that contain the commit. See https://stackoverflow.com/a/1419637/1301972 for a more thorough treatment of the various options, as well as some discussion of the possible use of git-cherry under certain circumstances.

However, if the commit was merged in from a branch that has since been deleted, the ability to identify the original source branch will be limited to data stored in non-fast-forward merge commits. Therefore, your mileage will vary.

Use Git Bisect Instead

In general, if you have a bad commit, you will want to take a look at git-bisect as a way to isolate the problematic commit or commits. This will let you do a binary search for good and bad revisions, and doesn't rely on source-branch information that may not be accessible in your currently repository.

Community
  • 1
  • 1
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199