Git: It is impossible to understand why the branch (theme) commits / merges occurs on the main branch

Note. I am not sure if this has already been asked, since I cannot find any question that matches my context (or I cannot understand the contexts of existing questions)

These days I love Git. In particular, the theme of branches. I am working on a small code-sharing application. And I have (local) branches like "master", "authentication", "bookmarks", "comments", "nose", etc.

My (supposed) workflow looks something like this: Create a topic branch ==> Work in the section branches ==> Commit the files in the ==> branch Combine the changes in the topic branch into the "master" branch. (And later delete the topic branch)

I tried to do the same for a couple of branches. It worked fine. But later, when I checked the Git schedule, even if I followed the same workflow, all the chances took place on the "host". No tree lines diverge or converge! From now on, it shows one single line with several commits. I'm not sure why? I have the impression I screwed something with a HEAD pointer?

To give a practical introduction, here is my Git timeline: http://github.com/none-da/zeshare/network

Here are the commands I used:

>> git branch authentication_feature >> git checkout authentication_feature >> # I work with all the files here in "authentication_feature" branch >> git commit -m "Authentication_feature is up" # commiting to the branch >> git branch # just to confirm, which branch I am working on >> git checkout master # trying to shift to master branch >> git merge --no-commit authentication_feature # I merge in two steps. This is step 1 >> git status;git add; git commit -m "Authentication_feature" merged to "master". # This is the step 2 >> git log --graph --pretty=oneline # confirming the graph >> git push origin master # pushing to the remote server(github) 
+6
git branch merge github commit
source share
6 answers

But later, when I checked the git chart, even if I followed the same workflow, all the chances were on the β€œmaster”. No tree lines diverge or converge!

Well ... I see some of your branches and merges.

You will find all possible merge scenarios on this page.
(compiled at the time - end of 2007 - now SO contributor: Jakub Narbsky )

You may be in an advanced case, which explains why your merges will make all your commits seem masters after they are completed:

2 / Fast forward; there are no commits A, B, C, and we start with the following situation:

  1---2---3 <-- trunk <-- HEAD \ \-a---b---c <-- branch 

2.1 / " git merge branch "

  1---2---3 /----- trunk <-- HEAD \ v \-a---b---c <-- branch 

Fast forward leads to a simple movement of the head of the body.
It does not create a commit, therefore:

2.2 / " git merge --no-commit branch "

As in 2.1, because expedited forwarding does not create a commit.

So, if you are not committing to master since you forked and then merge with master, all you do is reset master HEAD ...


Another reason why the branches do not appear is the to-do list effect described on the presentation page.

But you see each commit only once. Let it sink for a second.
I find that many coders are so used to centralized SCM that they miss the fact that our graphical visualizer actually shows and connects disparate repositories.

If I draw the graph with me as root, then the graph shows the view of the to-do list, which I have not yet drawn into my repo.
When I want to catch up with what the community is doing in my forks of my repo, I can get into the schedule and immediately see what others have been doing. If I had to change the changes in Bertgs, then the next time I see the schedule, Bertg will no longer be shown, because it will no longer have any commits that I do not do.
Continue browsing the to-do list and you will understand the schedule.

So, if this is true for mergers with other repository branches (i.e. you no longer see these branches after merging them), this may be true for mergers from your own repo branches: after merging, you no longer see them in your chart.

But I, since:

I do not own the project. Maybe I want to make changes to the repo from any of your branches.
+5
source share

I'm sure you are looking for the switch --no-ff to git merge . By default, merge will simply update HEAD to the end of the new branch if there is no intermediate commit.

If you want to leave a merge commit to help group your commits, go --no-ff .

+7
source share

You did not say which commands you actually used, but I assume that you created your branch using git branch , but did not check it to go to the branch. You can do this in one step as follows:

 git checkout master -b topic22 

This reduces the likelihood that you will inadvertently perform the master.

Now that you have added the sequence of commands you made, I see that you checked the branch.

The sequence of commands looks fine. I think the reason is that there was no branch, because there was no intermediate commit on the main branch. After the merge, it looks like a sequential stream of development. This is well discussed in one of the other answers, so there is no need to describe it in detail here.

0
source share

Are you using something like

 git show-branch 

to show you the branches and accounts, as soon as you merge your branches to deal with them, you no longer see the changes - you don’t know why.

I can not find any explanation about the behavior, but the problem with the git repository does not occur, since git log shows all the commits for each branch.

So, I think this is just a way to display the branch graph.

0
source share

I am new to git and github myself (and the link still does not work), but looking at your steps, maybe because you did not push the actual branch to github? This seems to work for me so far (I inserted the push command):

 ... >> git commit -m "Authentication_feature is up" # commiting to the branch >> git branch # just to confirm, which branch I am working on >> git push origin authentication_feature # push the branch to github >> git checkout master # trying to shift to master branch ... 
0
source share

As an alternative to using git merge --no-ff :

If you want to convey the effect of the topic branch development to the main branch, but not all individual commits, then you can use git merge --squash . When you do this, the commit is not marked as a merge and does not have a second parent to the topic branch. A list of individual commits is included in the commit comment for compressed merging, as they will be listed by git log .

We used this in a project that is related to SVN ( git svn ), so our main branch has a linear history. Thus, we do not need to align the git commit graph before running git svn dcommit .

0
source share

All Articles