by crazypython · 6y ago · 0 comments
A branch is a name that points to a git commit. Every git commit has a parent, so a branch also has all its parents. You have a current commit, known as HEAD, and you have a current branch.
Merge is when you make a commit that "fuses" two commits, leaving both in the repository. It is ugly.
Rebasing is when you reapply the diverging commits of a branch onto the commits of another branch. You give it a new base."
This is important: Branches are names for commits. I have two active branches currently, "floating-plugins" and "master." "floating-plugins" is where I'm working on a plugin system and inter-plugin communication. I made the logging system log a stack trace for warnings. When I did and tested this change, I quickly select the lines of code that bring about this change through a GUI, type in a short message, and commit. Suddenly, I need to implement a feature on "master." As I'm implementing it, I realize I also need the log-stack-trace-on-warn feature in master. So I rebase with floating-plugins, and now, I have that feature on master.
In another scenario, I might have had to reorder the commits on floating-plugins so I could safely rebase to just the commits I wanted on master. In yet a different scenario, a cherry-pick might have been appropriate. The unifying theme of all this is that you need to be able to visualize Git.
Git won't fix people who do not test in a disciplined way. That's a social problem.
Git let's me do a hotfix on a beta testing server while having other code on my current laptop, and then merge the changes together with a rebase.
Didn't you just break the golden rule of Git which is to never rebase onto a public branch?
The fact that a) there even needs to be a golden rule, b) it's not obvious c) not everyone knows about it ... and I'm sure for many other reasons is a very strong reason to be spooked.
Git is like uranium, powerful, but so many don't even know what they are getting into.
Or maybe it's like C++ - really dangerous, but after a while, you learn to avoid most of the pitfalls and then it starts to feel 'ok' even though such pitfalls shouldn't exist in the first place ...
[1] https://www.atlassian.com/git/tutorials/merging-vs-rebasing#...]