A Branch is just an object representing a git head link. A head is a text file mainly living under the .git/refs/heads hierarchy. This text file contains the commit hash that this head points to. Similarly, a Branch has a Tip property that points to a commit .
When working with git repositories and performing actions such as commit, reset, reload ... the head file is updated with different hashes, indicating different commits.
A head does not track previous commit indications. In addition, Branch .
With git, when creating a new branch, a new refloc is created. git will take care of adding the first entry with a message identifying the object from which the branch was created.
Given the existing backup branch
$ cat .git/refs/heads/backup 7dec18258252769d99a4ec9c82225e47d58f958c
Creating a new branch will create and send it a reflog
$ git branch new_branch_from_branch backup $ git reflog new_branch_from_branch 7dec182 new_branch_from_branch@ {0}: branch: Created from backup
Of course, this also works when directly creating a branch from a commit.
$ git branch new_branch_from_sha 191adce $ git reflog new_branch_from_sha 191adce new_branch_from_sha@ {0}: branch: Created from 191adce
LibGit2Sharp also provides reflog. For example, the following code will list log entries for a specific Branch .
var branch = repository.Head; // or repository.Branches["my_branch"]... foreach (ReflogEntry e in repository.Refs.Log(branch.CanonicalName)) { Console.WriteLine("{0} - {1} : {2}", e.From.ToString(7), e.To.ToString(7), e.Message); }
So, “good news,” reflog may contain what you need -)
but...
- you will need to find the correct entry yourself by searching in each message "branch: created from template
- If your branch is too old, older reflog entries can be deleted with the built-in git gc (by default, reflog entries are stored for 90 days), and the original “Created from” entry can now be lost.
Note. . To date, LibGit2Sharp does not create a create entry when creating or deleting a branch. However, this is currently being considered by awesome @dahlbyk as part of Request Pull # 499