Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit option to split branches in the network graph

On my git network graph, I want to keep branches separated. However if I have a circumstance where I split my master to branch A, then make one or more commits to A, then merge it back to master, the graph shows a single line for both master and A, despite the fact that at least one commit point was not included.

In other words, my graph looks like this:

*------*------*------* (master/A)

And I want it to look like this:

*------*------*------* (master/A)
 \__________________/

I know there's an option either in commit or push to force this (and I did it once, ages ago), but for the life of me I can't find it.

Does anyone know the command to do this? And second, for extra credit, its location in Android Studio?

Thanks!

like image 527
Scott Avatar asked Jan 18 '26 03:01

Scott


1 Answers

As Mykola said in a comment, the answer is:

git merge --no-ff

The normal behavior of a git merge is to "fast forward" the base branch HEAD up to the place where you are on your new branch. This effectively erases your new branch (A in the example above). Specifying "no Fast Forward" adds a new commit and preserves the existence of Branch A for posterity.

Also see: http://www.relativesanity.com/articles/ffwd

Bonus Answer: In Android Studio, it's possible to use the no-ff option. However you cannot use the quick branch menu on the bottom right where you select the branch and click merge. You need to go the "long" way - From the top menu, select VCS/Git/Merge Changes. This will give a dialog box for the merge allowing you to set options, including "No fast forward"

like image 177
Scott Avatar answered Jan 19 '26 20:01

Scott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!