TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Commit often, perfect later, publish once: Git best practices (2013)

261 pointsby hidden-spyderalmost 4 years ago

23 comments

cjfdalmost 4 years ago
I kind of feel that this kind of git advice is way beyond the point of diminishing returns. As a conscientious developer we have a lot of work. We write code of good quality. We refactor that code regularly. We write automated tests. We test the program manually. We use linters and type checkers. We talk to people to find out whether what they requested is actually what they need. But the day only has 24 hours. At some point one has to say that enough is enough. I really want to put the 'enough is enough' point before worrying about a good looking commit history. Some years ago we all went from svn to git and I am not really sure the improvement was worth it. Sure, git is objectively the better version control system. One can do a lot more things in git. But then the disadvantage is that one actually gets to think about all of these 'a lot more things'. One thinks about questions like should one merge or rebase and so on. I seems like an activity that falls under what is commonly called 'bike shedding'. But like I was asking before: is this really worth it?
评论 #27730845 未加载
评论 #27728299 未加载
评论 #27728556 未加载
评论 #27728073 未加载
评论 #27728810 未加载
评论 #27728283 未加载
评论 #27728044 未加载
评论 #27728292 未加载
评论 #27728382 未加载
评论 #27728404 未加载
评论 #27728613 未加载
评论 #27728237 未加载
评论 #27728916 未加载
评论 #27730553 未加载
评论 #27731181 未加载
评论 #27732494 未加载
评论 #27731305 未加载
评论 #27739839 未加载
评论 #27730624 未加载
letmeinherealmost 4 years ago
&gt; Does this mean one per product, program, library, class? Only you can say. However, dividing stuff up later is annoying and leads to rewriting public history or duplicative or missing history. Dividing it up correctly beforehand is much better.<p>Got it, simply devise the correct level of modularization for an increasingly complex project at the beginning of time, to avoid annoyances. Easy peasy. &#x2F;s<p>Git actually has tools to separate paths into their own repositories with intact histories, so I recommend the opposite.
评论 #27729993 未加载
globular-toastalmost 4 years ago
One of the more challenging parts of git for people to understand is that many of its tools and concepts serve many purposes. Commits are a good example of this. To git, a commit is a very simple and precisely defined thing. But what they represent is basically up to you.<p>One thing they could represent is your current work as of this minute. This is really useful to you while you&#x27;re working in case you break something and need to revert. But it has very little use to anyone else. Nobody needs or wants to know the history of a project down to the minute. How long it took you to develop a feature and how many times you messed up is completely irrelevant to the project a week from now. So these commits should remain private.<p>Another thing they could represent is <i>versions</i>. What&#x27;s a version? It&#x27;s a fully valid and working copy of the project that anyone could use. These are the commits that should end up on the master branch. Sometimes it&#x27;s possible to write these first time (for bug fixes or trivial stuff), but most of the time they need to be curated and constructed from the work done using the previous type of commit.<p>If history is worth keeping, it&#x27;s worth maintaining. If you don&#x27;t think it&#x27;s worth, delete your history.
lamontcgalmost 4 years ago
&gt; Once you git push (or in theory someone pulls from your repo, but people who pull from a working repo often deserve what they get) your changes to the authoritative upstream repository or otherwise make the commits or tags publicly visible, you should ideally consider those commits etched in diamond for all eternity.<p>I&#x27;ve broken this rule multiple times per day for the past 10 years.<p>On your own feature branches, rebase your fucking shit and force push. I see so many people creating ungodly messes because they never want to erase the history of PRs that they&#x27;ve submitted and its just a nightmare of merge commits pulled back into their branch from master.<p>I&#x27;ve watched a decade of git n00bs practice this &quot;never under any circumstances rewrite history&quot; advice and it fucks them up over and over and over again.<p>Nobody actually cares about the exactly commit process you went through to fix the bug. Squash everything and rebase. Leave a SUMMARY of why you did what you did in the PR and&#x2F;or commit message. Humans have this amazing ability to write stories about what they did after the fact.<p>I&#x27;ll frequently leave my-future-self notes on closed and merged PRs as I think about them post-merge, where I document what approaches were rejected, and what approaches might be worthwhile if the change isn&#x27;t sufficient. Stuff like &quot;I could not do WWWW because of &lt;great sadness&gt;, so instead we must do XXXX, if this is not sufficient because &lt;unlikely edge condition turns out to be not so unlikely after all&gt; then we must consider that YYYYY will be less preferable due to &lt;stuff i was thinking about hard&gt; and we should consider doing ZZZZZ first&quot;. If all you do is capture &quot;what did I change&quot; and don&#x27;t capture your thinking and what you view to be all the different alternatives while your mind is still fresh with the problem then you&#x27;re just throwing away useful information, which is what the &quot;preserve your git history&quot; approach does.<p>In the future, when I read my PRs I just don&#x27;t care about how I got there. I care about what I was thinking about. So I write down, long-form, what I was thinking about. A git history is about going from A to B, it might document why you bailed on going to C, but it probably doesn&#x27;t capture the stuff you rejected the whole time like D E and F and why. And really I&#x27;d PREFER to read a good note on why C sucked as a solution. I don&#x27;t need to see the code that went down the route of C until it turned into a mess and then had to be backed out.
评论 #27732857 未加载
评论 #27732715 未加载
评论 #27739236 未加载
heuriskoalmost 4 years ago
I don&#x27;t know if anyone felt the same way, but I felt I &quot;knew&quot; how to use git before I read tutorials about how to use git.<p>Sometimes I felt tutorials were making it seem harder, more mystical, than it really was, or relied on &quot;marble diagrams&quot; with arrows pointing backwards, which I felt was unintuitive.<p>I had used SVN quite a bit, and found you can use git in pretty much the same way, but branching was easier.<p>And if you&#x27;re using branches more, then &quot;rebasing&quot; your branch made sense, and the fact that you could &quot;rewrite history&quot;, which I remember to some people seemed controversial, but the idea was it was fine, if you kept your branch private, or added caveats.
评论 #27729917 未加载
jupedalmost 4 years ago
This is still pretty superstitious, even if it&#x27;s better than a lot of the stuff Github has unfortunately trained people to do. Maybe I&#x27;m naive, but I don&#x27;t think git usage has to be based on superstition and fear. I have never not been able to clear up people&#x27;s random-internet-post-induced &#x2F; github-induced confusion in about half an hour of personal communication.<p>Your goal in making a history is to make a meaningful, useful history that expresses information. I don&#x27;t think this is hard. I think a lot of people don&#x27;t want to do it, which isn&#x27;t my problem (unless I have to work with you), but I also think a lot of people do want to do it and are stymied by posts like this, or by services like Github.
fuzzy2almost 4 years ago
I agree with most of TFA. However, I urge everyone to start with a monorepo. Splitting a single project (developed by one team) into multiple repos will seriously slow things down later. I&#x27;ve seen it happen.
评论 #27729206 未加载
chiefalchemistalmost 4 years ago
I use Git the best I can (read: I am by no means Mr Git). I try to read these type of articles and I too often feel inadequate (i.e., there&#x27;s not enough explanation on what, why, and why that matters). Real life examples would help a lot. Else I have to try to imagine the appropriate situation for each recommendation; and frankly I can&#x27;t always do that. There are more possible scenarios than I have experiences.<p>There&#x27;s got to be a better way. Does learning and&#x2F;or using have to feel so complicated?
jdowneralmost 4 years ago
I am beyond sick of hearing about &#x27;best practices&#x27; for everything. It is such an obnoxious statement! So often it is used as replacement for &#x27;in my opinion&#x27; because it brooks no argument -- these are the BEST practices!
评论 #27731240 未加载
darepublicalmost 4 years ago
Create a branch, do frequent commits with messages like &quot;wip&quot;, &quot;bug city&quot;, &quot;wtf&quot;, prior to merge squash and create message referencing the objective of the commits and what they accomplished.
评论 #27732612 未加载
rendallalmost 4 years ago
Some great advice. Interesting the explicit references to IRC and email, which is (unfortunately? perhaps?) out of date in these days of github issues and Slack.<p>The original article is 2012 with PRs back to 2016.<p>My current gig is part of a microfrontend&#x2F;microservices scheme where each team owns the entire vertical from concept and design through full stack, and there are, gee, 40+ services working in concert with more planned. All of these merge into a single web application. It all works shockingly better than might be expected, but it takes a culture of constant vigilance and care along with automated integration including lerna, yalc, renovate, artifactory, et. al.<p>For our team, the branch management scheme is 1 branch per JIRA ticket, then PR with automated checks including tests, lints, code review. The dev decides whether to merge, squash or rebase to master with some input from the lead. That master is just for the microservice, which may or may not need to be merged into another parent service.
评论 #27729623 未加载
bcrosby95almost 4 years ago
&gt; If you think about it, movies are made this way. Scenes are shot out of temporal order, multiple times, and different bits are picked from this camera and that camera. Without examining the analogy too closely, this is similar to how different git commits might be viewed. Once you have everything in the “can” (repository) you go back and in post-production, you edit and splice everything together to form individual cuts and scenes, sometimes perhaps even doing some digital editing of the resulting product.<p>Except the end product is a movie, and my end product is software, not a commit history. If you want to draw an analogy to movies, then rebasing your history would be like movies throwing out raw camera footage because they have the end product. They keep <i>all</i> of the <i>raw</i> footage. They do <i>not</i> throw it out by &quot;rebasing&quot;.
andreineculaualmost 4 years ago
I haven&#x27;t read it all but this could be great material as a git-mindset booklet for a team. Great to see someone taking the time to put down common sense notes about working with git, rather than yet another dry &quot;this is how git works&quot; or &quot;this is how you should use git (because i told you)&quot;.
lukicdarkooalmost 4 years ago
In my workflow, I typically commit often and use the commits as personal checkpoints. Once a pull request is ready I simply squash the commits and merge. That way, the history in the main branch is clean and I have my checkpoints. I assume that is a typical workflow for many teams.
评论 #27728799 未加载
Dumblydorralmost 4 years ago
I&#x27;m a beginner at Git. I coded in a hospital system where I was told not to use Git. Upgraded jobs, now I&#x27;m using it for the first time.<p>Wow! What a difference. I have to say the ability to see what I&#x27;ve done over time, to not have endless files labeled with the date and my initials, not having to manually write down what I&#x27;m up to...this is heavenly.<p>My main gripe would be the opaqueness of git. It really wasn&#x27;t intuitive, I had to use it a few days before the vocabulary made sense, push, pull, commit, add, origin, they didn&#x27;t logically click for me that fast.
评论 #27730129 未加载
评论 #27731079 未加载
SergeAxalmost 4 years ago
I beleive that in feature-branch workflow it is totally okay to rewrite history of the branch before merging it into master. The only case when it is obviously wrong is when several engineers are working on the same feature branch, which is against all methodologies known to me (except the duration of code review, when reviewers may pull the branch to run tests or use IDE on it).<p>Having atomic semantic idiomatic changes in history beats short term branch immutability with one hand tied.
29athrowawayalmost 4 years ago
This is not a best practice.<p>Detecting problems is finding a needle in a haystack.<p>If you want to be efficient at finding the needle in the haystack, you make the haystack smaller.<p>That is what code review is about. You do not scan the entire source code for defects, only the new code being added.<p>You can commit often to your own branch, and submit for code review once it&#x27;s stable.
dangalmost 4 years ago
Discussed a bit at the time:<p><i>Commit Often, Perfect Later, Publish Once: Git Best Practices</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6138928" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6138928</a> - Aug 2013 (4 comments)
daitangioalmost 4 years ago
My simple strategy was to avoid fast-forward on merge and to use &quot;git pull --rebase&quot; when my changes are not critical. History rewriting? Hum I do not know....I do not like changing history
mtVesselalmost 4 years ago
&gt; &quot;...your work will not be lost for at least two weeks unless you really work at it&quot;<p>What happens after two weeks?
评论 #27730033 未加载
mattgreenrocksalmost 4 years ago
&gt; [don’t] use checkout in file mode<p>What is the alternative? Sometimes I edit a file and don’t need the changes after all.
评论 #27731951 未加载
copiratealmost 4 years ago
&gt; Personally, I commit early and often and then let the sausage making be seen by all except in the most formal of circumstances. [...] For a less formal usage [...] I let people see what really happened.<p>&gt; Whenever I pull, under most circumstances I git pull --rebase.<p>These 2 statements are contradictory. By doing a &quot;pull --rebase&quot; you hide the (maybe important) fact that your commits were written in another context.
laurent92almost 4 years ago
GDPR and GIT: Should we have personally identifiable usernames&#x2F;emails in Git?
评论 #27729690 未加载
评论 #27732520 未加载