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?
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)"
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With