How is a revision related to a property branch after a merge?

One of the biggest surprises for me when learning Git was the fact that revisions are not permanently associated with a particular branch; rather, the branch simply indicates a specific revision. When I fully understood this concept, I realized that I did not understand how to really use this function properly.

I read, apparently, the famous essay on the successful Git forking model , which displays branches as strings, as well as revisions as being clearly linked to one line. Consider this passage:

enter image description here

Two function branches are shown here (name them featureA and featureB ) and the develop branch. Moreover, featureB completely merged with develop , and then again diverged, only for re-merging.

It looks beautiful, neat and understandable, and it also happens that the repo will literally look at the end of this process in something like Mercurial. As I understand it, I like it, and I would like to develop this way (and I did it in Mercurial). However, in Git, the final state does not look like this. It looks like this:

enter image description here

In other words, the only information that we have about the two branches of features is that they now have the same revision as the development branch. As a result, we can do our best for the whole tree:

enter image description here

In other words, all this good information about the history of how the development took place is lost; he never recorded in the first place. Notice how in the first chart the three revisions are clearly on featureB before they are merged into develop , but I don’t see how we can know that these three revisions were on featureB before the merge.

It is right? Is it the above, I can recover from a fact in Git, and so the screenshot from the essay is more likely to be misleading? Or is there something important that I'm missing?

+4
source share
3 answers

Yes, that’s right, the three branches (pointers) will just refer to the same commit.

But with git, it's more about a sequence of commits than a branch.
A branch is just a pointer to the commit graph to:

  • Help your local developer quickly switch to one or combine one with the other
  • help publish (by clicking) the upstream repo collection of commits (you do not push all branches by default, only one wants to be public).

If you really need to store " featureA " somewhere, it will be in the commit message, but there is no need to specify a branch: you can choose a commit with a cherry, reconnect the branch, rename delete (pointer) at any time.
After all, the story told by the sequence of commits is more important than the fact that the commit belongs to or belongs to one or more branches.

+2
source

You are partially right, but also something is missing. Git is all about the sequence of commits and the schedule they create. But you are missing three things on your final chart:

  • (minor) Your last merger is the merger of an octopus (the merger of more than two branches). You would not do this in this situation, and I do not know why the image from git -flow also contains.
  • Merge parents have an order. Thus, there is a first parent and a second parent. In other words: Git writes down what was merging in .
  • Mergers have a commit message

Thus, you can easily restore the development branch, starting from its head and following only the first parent ( git log --first-parent ).

If you want to know which function has been merged, you can see the commit message in the merge.

But note that this is true if you use Git in this way. Merging featureA in develop and merging develop in featureA will have very similar results, and many people will not realize that it is a difference.

+1
source

As @VonC pointed out, in git -land (unlike Mercurial World? :-)) it often seems like this is considered a sign, or at least not a mistake. But if you want your tags to be stored in different places, you can do it in git by doing your merges with --no-ff . This would otherwise create an “unnecessary” / “empty” merge merge, which serves to keep the parent pointers separate and therefore serves to branch branches.

0
source

Source: https://habr.com/ru/post/1491414/


All Articles