Reputation: 10419
In git it is possible to create a new branch from a specific commit from an existing branch.
git branch newbranch 32234234234kjh23k4h2...
Is is possible to check what branch / commit a branch was created from?
Upvotes: 0
Views: 70
Reputation: 168988
In git it is possible to create a new branch from a specific commit from an existing branch.
Yes, just as you have noted. git branch name commit
will create the branch name
that points to the commit commit
, which can be a commit identity (hash), branch name, or any other commit specifier.
Is is possible to check what branch / commit a branch was created from?
Not definitively, unless you are working in the same repository that the branch was created from, or you have direct access to the central repository, and if the reflog for whichever repository you are looking at has not been pruned. You can use git reflog branchname
to get a list of every commit the branch has ever pointed to. If running this on a local clone, and the branch was created in a different clone then this technique will not yield completely accurate results.
If you don't have direct access to the central repository or the clone where the branch was first created, you will have to look at the commit history of the repository and try to infer from context where the branch was initially created.
Upvotes: 1
Reputation: 55718
A branch is more or less just a named pointer to a commit. As such, it has only information about the HEAD commit of a branch. That commit has one or more parents which you can use to track back the history of the branch, but it is not possible to retrieve the starting point of a branch as that information is just not saved. Thus, any commit in the parent chain of a branch's HEAD commit could be the starting point.
That said, some GUIs display a branch graph where they take into account branching points which they identify by the existence of 2 or more commits which share the same parent commit. Apart from that, there is nothing available to identify a branch.
Upvotes: 1