3 ms·
People need to learn Git. Git has a "click" moment. Git "clicked" for me a few weeks after I began using GitUp, an FOSS Mac app. It visualizes Git, and doing ad
by crazypython 7y ago
People need to learn Git. Git has a "click" moment. Git "clicked" for me a few weeks after I began using GitUp, an FOSS Mac app. It visualizes Git, and doing advanced Git is easy from within there, and only committing some lines of code is easy from within it. Visualizing Git is really helpful.
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.
- jariel 7y ago"So I rebase with floating-plugins, and now, I have that feature on master." Didn't you just break the golden rule of Git which is to never rebase onto a public branch?
- earthboundkid 7y ago“Rebase” is a bad name for what should be called “edit history”. Never edit the existing history of master. Always do edit the history of other branches to merge them into master.
- CameronNemo 7y agoIs that really a rule? We do that all the time.
- jariel 7y agoThe Golden Rule of Git [1] 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#the-golden-rule-of-rebasing https://www.atlassian.com/git/tutorials/merging-vs-rebasing#...]
- CameronNemo 7y agoRebasing onto a public branch and rebasing while on a public branch mean completely different things. The first happens all the time, the second creates problems for people doing the first.
- jariel 7y agoPardon my ignorance, but if you rebase while on master, are you not changing the master branch history for everyone? Isn't the point of the golden rule to not be re-writing the history of public branches?
- CameronNemo 7y agoThat is exactly what I was referring to in my comment. We are saying the same thing.
- jariel 7y agoOh, ok yes, I see. Again it troubles me that even the language of Git is sometimes ambiguous. I feel that there should not be a 'golden rule' of something that should never be done - it's a flaw in the product. It simply should not be possible, or at least not with someone without super-admin rights. I feel Git is very much an administrative level tool, and that there should be something else for devs; something that is fairly obvious, consistent, encourages/forces the org. the policy and makes it so that devs don't have to think to much and really hard to screw up. Admins can give special privileges to the 'true experts' on an as-needed basis.