Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git branches & commits history after merge

Tags:

I'm working on a project (alone) and for every feature I develop I create a new branch, work on this feature, then merge it to master. So normally I never work on two different branches at one time and never touch master while working on a branch.

When I merge a branch I see that (using gitx and gitk) the history of master branch gets all the commits I've done to the merged branch. I mean if I have something like:

master a-b-c-d               \z-x-y--               |branch name 

after merge I get:

a-b-c-d-z-x-y             |branch name 

Yes, I see the merged branch name highlighted (using gitx and gitk), but what I was expecting is something showing exactly where commits are done (to which branch) like:

master a-b-c-d--------M--               \-z-x-y-/               |branch name 

So I'm expecting to see a commit "M" that represents the merge I've done to master, not to look like that all commits I've done to the new branch have been done to master.

Is my expectation correct? Or this is normal git behaviour?

like image 262
Ansd Avatar asked Sep 01 '11 18:09

Ansd


People also ask

How many branches are there on Git?

There are five different branch types in total: Main.

What are branches and commit?

A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master . As you start making commits, you're given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically. Note.

What is main branch in Git?

There is nothing special about the main branch. It is the first branch made when you initialize a Git repository using the git init command. When you create a commit, Git identifies that snapshot of files with a unique SHA-1 hash.


1 Answers

That is normal Git behaviour. You are doing what is called a "fast-forward" merge, because your branch is strictly ahead of the master branch.

If you really want to preserve branch history (although I'd recommend you don't bother) then you can use git merge --no-ff to force it to create a merge commit even when it can do a fast-forward update.

like image 53
Cameron Skinner Avatar answered Sep 30 '22 12:09

Cameron Skinner