Skip to content

Instantly share code, notes, and snippets.

@jelaniwoods
Last active June 25, 2020 19:07
Show Gist options
  • Save jelaniwoods/7ba111862751d6262cb3f841c35f5c60 to your computer and use it in GitHub Desktop.
Save jelaniwoods/7ba111862751d6262cb3f841c35f5c60 to your computer and use it in GitHub Desktop.

Take this git graph as an example:

* ef99623 (c-branch) Other spaces
*   3c391fc (master) Merge branch 'b-branch'
|\
* | f0c357b Add spaces
| | * bc9833b (HEAD -> b-branch) Another space
| |/
| * 64d6e33 update
|/
* f716b36 rails new

The Ruby git gem requires me to go through each branch to get the commits—

c-branch

ef99623 (HEAD -> c-branch) Other spaces
3c391fc (master) Merge branch 'b-branch'
f0c357b Add spaces
64d6e33 update
f716b36 rails new

b-branch

bc9833b (HEAD -> b-branch) Another space
64d6e33 update
f716b36 rails new

master

3c391fc (HEAD -> master) Merge branch 'b-branch'
f0c357b Add spaces
64d6e33 update
f716b36 rails new

The issue I have is that the commit 64d6e33 update was made on b-branch, but after the merge, I don't know how I can determine the commit was created on b-branch and not master from looking at the logs.

To clarify, all I can determine from ruby-git is:

  • I can loop through each branches log
  • For each commit I can access the parent commit(s)

Inheritely branch names are not stored with commits, so determining what branch a commit was created on is really tricky— especially when merging is involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment