1

I'm studying design patterns in python and I'm doing version control in git. The first thing I did was create a branch called "Creational Patterns", in which I made a commit for each one (Factory, builder...etc) Later I created a new branch called "Structural Patterns" and moved to it. I have been committing to this branch for these patterns. However when I went to see the history of my "Structural Patterns" branch, there are also the creational pattern commits! I think git is doing fast-forward merges, however I have the following question: Is it possible to have this branch of structural patterns without the commits of the creational patterns branch? or git will always do this automatically. Thank you very much!

Diego L
  • 185
  • 1
  • 9
  • By default, when you start a branch, it will use the commit where you are (or any other you provide) to create its content and its history.... you can optionally ask git not to bring over the history of the branch that you are using as the base using `--orphan` (`git checkout --orphan a-new-branch`). – eftshift0 Nov 02 '22 at 14:16

1 Answers1

0

You switched the branch from your "Creational Patterns" branch. It is a difference, if you start a new branch from your main branch. If you create a new branch it will create a branch from the point you are currently at. (If that is a different branch, it will take that)

You will need to rebase your branch. @torek has a long answer to this on another question. You can look it up here: How to change the starting point of a branch?

torek
  • 448,244
  • 59
  • 642
  • 775
Fexo
  • 179
  • 7
  • That is, whenever I create a branch from a branch that already has commits, will I take this commit history? I thought it only took the last commit of the branch from which I created the new branch. The command I used while on the "Creational Patterns" branch was: git checkout -b "Structural_Patterns". Thank you very much for your prompt reply :) – Diego L Nov 02 '22 at 14:22
  • No! It is correct as you said. Sorry. Did I misunderstand you? It will take all commits of the branch you created from. This does not apply to new commits, unless you rebase the branch. Example: Main has commit 'a'. Branch Creational Patterns has commit 'b'. With your command branch "Structural Patterns" will start with commit 'c' – Fexo Nov 02 '22 at 14:24
  • Thank you very much for your help! It turns out that when I created the "Creational Patterns" branch I didn't have any commits in main... So it turns out that "Creational_Patterns" is my main!, so when I created "Structural Patterns" git has done fast-forward merges with main ("Creational patterns). Your answer has helped me a lot!, next time I'll do things right hehe" – Diego L Nov 02 '22 at 14:50