0

I have this command:

git log --pretty="%D" -n 2962c2b8dbd4bf78d90f228527c3cb65c4cea3b0

Result is:

HEAD -> master
local_branch




... and many many many more lines are printed out by this command. Sometimes there are outher branch names

When i try:

git log --pretty="%D" -1 2962c2b8dbd4bf78d90f228527c3cb65c4cea3b0

This is the result (two empty lines):


How do I achieve that I get only the first "line", or the first branch name?

Why is the output of the first command so long? And why does the second command output 2 lines, though I limit it to just one line with -1?

I'm really desperate :(

KodJunk
  • 11
  • 1
  • 4

1 Answers1

0

If I understand your question, you are looking for a command which will output the branch on which the commit was originally made.

git log --pretty="%D" -n 2962c2b8dbd4bf78d90f228527c3cb65c4cea3b0

This will output the refs of all branches on which the commit can be found, which, if the commit has now been merged to other branches (eg. master) will include those branches.

You could try:

git log --merges <commit>..

To find where the commit was first merged and there for its original branch. This will only work if the commit was not merged via fast forward.

See this answer for more info on this topic:

Finding what branch a git commit came from

Will Taylor
  • 1,650
  • 9
  • 23
  • Ahh ok. But i want to look for the second branch, in my case the master branch. My workflow: I've cloned the master. I made changes and committed them into the local_branch. Then i merged ot into the local master and at the end i pushed it. I want to output the name of the master the local_branch was merged in. I am using the sha of the merge commit to the local master. – KodJunk Aug 29 '19 at 15:46
  • `git log --merges ..` should be enough for you to find merge commit that was created when you merged local_branch to master, this merge commit's message should contain the names of both local_branch and master. – Will Taylor Aug 30 '19 at 10:26