views:

375

answers:

6

Note: I am not sure whether this has been already asked, as I can't find any question fitting to my context(or I am unable to understand the existing questions' contexts')

I am loving Git these days. Especially, the topic branches. I am working on a small code sharing application. And I have got (local)branches like "master", "authentication", "bookmarks", "comments", "nose" etc...

My (intended)workflow goes something like this: Create a topic branch ==> Work on the topic branch ==> Commit the files to the branch ==> Merge the topic branch changes to the "master" branch. (And later delete the topic branch)

I tried doing the same for a couple of branches. It worked fine. But later when I checked the git graph, even if I followed the same workflow, all the chances were happening on the "master". No tree lines diverging and converging! It shows one singe line with multiple commits from then. I am not sure why? I am of the impression, I screwed something with HEAD pointer?

To give a practical view, here is my git graph: http://github.com/madhav/zeshare/network

Please help me on this!

Update: I apologize for not telling you about the commands I used. Here they are

>> 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)

And the github is temporarily down. Thats why the link was not working .

A: 

You did not say what commands you actually used, but my guess is that you created your branch with git branch but did not check it out to move to the branch. You can do this in one step as follows:

git checkout master -b topic22

This makes it less likely you will inadvertently commit to master.

Now that you've added the sequence of commands you did, I see you did checkout the branch.

The command sequence looks fine. I think the reason it looks like there was no branch is because there was no intervening commit on the master branch. After the merge, it looks like a sequential development flow. This is well discussed in one of the other answers so no need to elaborate here.

Jamey Hicks
@Jamey, I updated my question with the commands I used. Please advice where the problem is.
Maddy
I always found topic22 to be an interesting feature.
theIV
A: 

Are you using something like

git show-branch

to show you the branches and check-ins, once you merged your branches to master you can't see anymore revisions - not sure why.

I can't find any explanation about the behavior but there does not seem to be any problem with git repository since git log shows all commits for each branch.

So I guess it's just the way the tool displays branch graph.

stefanB
@stefanB, I updated my question with the commands I used. Please advice where the problem is.
Maddy
@stefanB, but github network graph should reflect how I commit and merge no? I am certain there is something wrong with the way I use the commands!
Maddy
A: 

I am brand new to git and github myself (and the link is still down), but after looking at your steps, could it be because you didn't push the actual branch to github? This seems to be working 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
...
Chris J
@Chris, you pushed the branch to the remote address, which is fine, but didn't merge to the master! And if you check the network graph link(if github is up by now), the approach I mentioned did create different lines(graph lines) of development, only previously. Its not doing now only :'( I am also new to git by the way.
Maddy
re: merge to the master - I cut out the other steps ("...")
Chris J
+4  A: 

But later when I checked the git graph, even if I followed the same workflow, all the chances were happening on the "master". No tree lines diverging and converging!

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

You will find in this page all the possible merge scenarios
(compiled at the time - late 2007 - by now SO contributor : Jakub Narębski)

You could be in a fast-forward case, which would explain why your merges will make all your commits appear to master once they are done:

2/ Fast forward case; there are no commits A, B, C, and we start from 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 results in simply moving the head of trunk.
It does not create a commit, hence:

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

Like in 2.1, because fast-forwarding does not create a commit.

So if you did not commit on master since you branched out, and then do a merge on master, all you do is resetting master HEAD...


Another cause for branches to not be displayed is the "to-do list effect" described on the presentation page of the GitHub Network Graph visualizer (which is the "git graph" you are referring to here)

But you are seeing each commit only once. Let that sink in for a second.
I find that many coders are so used to a centralized SCM that they miss the fact that our Graph Visualizer is actually showing and connecting disparate repositories.

If I draw the graph with myself as root, then the graph shows a sort of to-do list of code that I haven’t pulled into my repo yet.
When I want to catch up on what the community has been doing in their forks of my repo, I can hit up the graph and see immediately what others have been up to.
If I were to pull in Bertg’s changes, the next time I see the graph, Bertg will no longer be shown at all because he will no longer have any commits that I do not.
Keep thinking to-do list and you’ll understand the graph.

So if that is true for merges from other repos branches (i.e. you do not see those branches anymore once they are merged), that may be true for merges from your own repo branches: once merged, you do not see them anymore in your graph.

But I do, since:

  • I am not the owner of the project.
  • I may want to pull in my repo changes from any of your branches.
VonC
Oh! That makes me think! But if you see my project graph, I started seeing different branches at the starting and merged one and two. But later even if I did the same with another branch, I didn't see any similar diversions(which have happened previously) for that branch. It appears as if the whole commit is done on the master. I think thats the whole point. "git merge --no-commit" (which I mentioned before) is actually responsible for this issue. Isn't it?
Maddy
@Maddy: "`git merge --no-commit`" is not the cause here, if you are in a fast-forward merge scenario. See my edited answer.
VonC
`git merge --no-commit` : With `--no-commit` perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge result before committing. - so it means the code got merged but it's not recorder in git so you will not see any merge in graph, correct?
stefanB
@stefanB: correct. But if it is a fast-forward case, only master HEAD is updated anyway (commit or not). Then, Maddy do some modifications and commit, again on master. In that scenario (2.1 or 2.2), the branch will disappear from the graph.
VonC
Thanks Vonc! I really misunderstood the graph. As its said, the graph is about code and not ego! I wont be seeing the same graph(or branches) when my branch has already got those commits(pulling the changes in other branches!). Thanks a lot
Maddy
+6  A: 

I bet you're looking for the --no-ff switch on git merge. By default, merge will just update the HEAD to the tip of the new branch, if there's no intervening commit.

If you want to leave the merge commit around to help with grouping your commits, pass --no-ff.

John Stoneham
I started using this and I will never leave that.
Maddy
A: 

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

If you want to commit the effect of the topic branch development to the main branch, but not all of the 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 of the topic branch. The list of individual commits is included in the commit comment for the squashed merge, as they would be listed by git log.

We have been using this in a project that is linked to SVN (by git svn), so that our main branch has a linear history. That way, we don't have to flatten the git commit graph before running git svn dcommit.

Spencer