Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git graph not showing branch

Tags:

git

How come when I create a new branch and make commits to it I am not seeing it branch off in my graph.

Here is the code i am doing:

git init

git add .
git commit -a

... other commits in here

git checkout -b mynewbranch

git add .
git commit -a

git checkout master
git merge mynewbranch

git add .
git commit -a

This is what I expect to see in my mind when I perform git log --graph

* 47926e1 This is a commit back on master
 \
  * f3dc827 How come i am not seeing a branch in my tree
  * 1cd3018 This should be on my new branch  
 /
* 47f3716 This is my third commit
* 878b018 This is my second commit 
* 2db9f83 Initial commit 

But I am seeing this:

* 47926e1 This is a commit back on master
* f3dc827 How come i am not seeing a branch in my tree
* 1cd3018 This should be on my new branch
* 47f3716 This is my third commit
* 878b018 This is my second commit
* 2db9f83 Initial commit

Am I not understanding something?

like image 884
Bryan Anderson Avatar asked Apr 25 '13 14:04

Bryan Anderson


People also ask

How do I view a git log graph?

Git log graph examples The following images show the git log graph output for these commands: git log --graph --pretty="%ad" --date=short. git log --graph --pretty="%C(yellow) %s" git log --graph --pretty="%C(bold green) %(ar)"

What is git DAG?

The history in Git is formed from the commit objects; as development advances, branches are created and merged, and the history will create a directed acyclic graph, the DAG, because of the way that Git ties a commit to its parent commit. The DAG makes it easy to see the development of a project based on the commits.


1 Answers

If there are no commits to master while you are working on mynewbranch, your history will look like what you've shown. In that case, no actual merge is required; merged master is identical to the tip of mynewbranch. If this is the case, git will (by default) do what is known as a fast-forward merge; master's branch pointer is just updated to be the same commit as the tip of your merge. This usually results in a simpler commit history that is easier to work with, especially if work is also going on in remote repositories.

If you want to force the merge to be recorded as a merge in git, you can use the --no-ff option on git merge.

In git, it's generally considered good practice to avoid merges where possible.

like image 55
antlersoft Avatar answered Oct 23 '22 07:10

antlersoft