Home > Back-end >  How to tell which GIT child is a new branch?
How to tell which GIT child is a new branch?

Time:10-03

How's everyone doing? Have run into an issue with GIT where I can't determine which child node is on the same branch as the parent and which one is a new branch: git tree example for below commits

As can be seen, there are tags but no branch names in the local/remote project.

tag "3.2ECHO1.1" -> parent: d42624
first green commit -> child 1: c1749e
first pink commit -> child 2: 404c71

If I run any of the following commands:

git branch -a --contains c1749e
git branch -a --contains 404c71
git branch -a --contains d42624

the result is an empty line for each.

Question: given a git parent commit, how does one determine which child is on the same branch and which child was a new branch? I would like to recreate the exact structure of this project into a new project.

Thanks

CodePudding user response:

No child is ever contained by a parent. Children contain, i.e., are descended from, parents, and never vice versa. The arrows point backwards, not forwards.

CodePudding user response:

In git, branches don't really exist. A branch is actually recorded the same way as a tag, just moved more often: it points at a single commit, so that you can refer to that commit more conveniently than by its unique hash. From that single commit, you can reach every ancestor of that commit, back to the root of the repository, by following "parent" pointers.

I would like to recreate the exact structure of this project into a new project.

The structure of the project is the graph that you showed; it is recorded as a series of immutable commits, each of which has zero or more references to "parents" - 1 for a "normal" commit, 2 for a typical "merge commit". The parents are stored as an ordered list, and by convention the first parent is the commit which was checked out when a merge happened; so graph views will try to keep a line of first parents more straight.

There is no record of where branch pointers were created, moved, or deleted, so if the branches don't exist right now, you can't recreate them - and even if they do exist right now, you can't necessarily tell exactly what their history is.

given a git parent commit, how does one determine which child is on the same branch and which child was a new branch?

You have to flip this around: given the current location of some branch pointer, you can determine if a particular parent commit is in the current history of that branch. But go deep enough into the repository, and your commit will be an ancestor of every current branch; there is no way to choose which is the "must relevant" descendant.

  • Related