Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to find the original branch a commit was made to?

Michael Vytlingam
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2019

Hi there,

I ran into this issue when we were looking through our previous commits to find a certain bug.

After a branch is merged into our `develop` branch, it becomes really difficult to determine which branch a certain commit was initially made.

Example, a commit that was made a week ago and was merged in:

Screen Shot 2019-07-24 at 10.52.46 AM.png

Currently, to avoid this, we've started putting our ticket numbers in the commits themselves, which is a bit tedious. Is there a simple way to find the branch the commit was originally apart of?

 

Thank you.

1 answer

1 accepted

0 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 24, 2019

Hello @Michael Vytlingam,

No, this is not possible with Git because it doesn't track such information. Unlike, say, Mercurial, a branch in Git is just a named reference to a commit. When you add another commit to a branch, Git simply moves its reference to that new commit. Here's a chapter from Pro Git book which explains how branches work in Git in details.

Currently, to avoid this, we've started putting our ticket numbers in the commits themselves

This is actually the right way to go and a good habit in general. Commit message describes what are the changes and why they are made, while the ticket links to issue tracker which often contains even more context on what are the changes made for.

There're some tools and scripts out there which help with putting a ticket number from branch name (when present) into each commit message – this is done by adding a commit-msg Git hook. You might find this useful as it automates that otherwise manual routine.

Let me know if you have any questions.

Cheers,
Daniil

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events