I've used git-blame to find a particular commit. Now I want to find the branch that it originally came from. (From there, I'll use the branch name to find the particular ticket)
Let's define "original branch" as "the branch to which the commit was made before the branch was merged into any other branch".
It is based on "Find merge commit which include a specific commit". Find when a commit was merged into one or more branches. Find the merge commit that brought COMMIT into the specified BRANCH(es). Specifically, look for the oldest commit on the first-parent history of BRANCH that contains the COMMIT as an ancestor.
Take a look at config file, perhaps there is branch. <branchname>. merge entry, which would tell you what branch this one is based on. You can also try git show-branch <branch> master , as an alternative.
`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.
First, checkout the branch that you want to take the specific commit to make a new branch. Then look at the toolbar, select Repository > Branch ... the shortcut is Command + Shift + B. And select the specific commit you want to take. And give a new branch name then create a branch!
Like the others said, if the branch you are looking for isn't local to the repository on which you are blaming this commit (e.g. a branch only in the personal repo of a distant developer), you are screwed.
But assuming that sought-after branch is something you can see, and that of course you have the commit's hash, say d590f2...
, a partial answer is that you can do :
$ git branch --contains d590f2 tests * master
Then, just to confirm you have the culprit:
$ git rev-list tests | grep d590f2
Of course, if d590f2
has been merged in more than one branch, you will have to be more subtle than this.
That isn't really applicable in git. Branches are local concepts to each repository: one person's "local-stuff" branch can be quite separate from another person's "local-stuff" branch. If you do something like looking at your main integration branch, and your query commit, and removing all the merge bases between the two, you should be able to get a subtree of the commit history that may shed some illumination... or may not. e.g. if you trace up the link from the query commit towards "master" you should hopefully find merge commits with useful comments saying where the merge came from... but this information is just informational, not recorded in some way intended to be automatically retrieved.
e.g. gitk some-commit...master
(which is almost short for gitk some-commit master --not $(git merge-base some-commit master)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With