TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Minimum Viable Git for Trunk-Based Development

48 点作者 elischleifer超过 2 年前

14 条评论

scelerat超过 2 年前
This guy doesn&#x27;t understand rebase. Rebase is an organizational tool. it&#x27;s housekeeping for keeping your commits clean. One reason to learn how to do rebase is so that your feature branch is tidy so when you merge it to main, main itself is tidy. Another is that as you perform the exercise of cleaning up your commits you are performing code review, something that, up until this point, you&#x27;ve just been throwing at your co-worker without much thought as soon as all the tests pass.<p>&quot;But my feature branch gets squashed anyway&quot;<p>1. I believe that in itself is a mistake, especially as feature branches get large and, though you say you&#x27;re all for small feature branches, your commit history says you do something different.<p>2. You don&#x27;t clean up that giant merge commit message with all those &quot;WIP&quot; &quot;fixed stupid mistake&quot; comments in there.<p>Use rebase to keep your workspace clean and main&#x2F;master comprehensible to your colleagues.
评论 #33808015 未加载
评论 #33905380 未加载
itslennysfault超过 2 年前
I finally understand why some people are so against rebase. They&#x27;re doing it wrong.<p>I&#x27;ve always heard people talk about how it doesn&#x27;t scale, but I use rebase like 99% of the time, and have worked on projects with hundreds of ICs. This is the first time I&#x27;ve seen someone explain it in a way where I get it. NO I&#x27;M NOT FORCE PUSHING TO MAIN YOU SILLY NILLY! Turns out I&#x27;m &quot;squash rebasing.&quot; I guess I didn&#x27;t know I need to specify that.<p>I do it slightly differently tough. I use git commit --amend to build up a single commit as I go.<p><pre><code> git checkout -b blah-feature # do some work git commit -m &quot;Main description of my feature&quot; # do more work # no -m, and then I just add bullet points for each subsequent change in vim (example below) git commit --amend </code></pre> Then, once I&#x27;m ready to make a PR I do the following:<p><pre><code> # pulls from remote without merging git fetch origin main # adds my single commit to the end of the current main git rebase main # push up feature branch for code review git push # get yelled at about --set-upstream, and copy&#x2F;paste that command :-) </code></pre> My commit messages typically look like:<p><pre><code> Add some new feature - do some sub task - do another sub task - ...</code></pre>
评论 #33808413 未加载
评论 #33805920 未加载
评论 #33804506 未加载
评论 #33807919 未加载
评论 #33804741 未加载
评论 #33806766 未加载
dboreham超过 2 年前
&gt; git add -A .<p>&gt; Add everything I’m working on (new and edited files).<p>Bad idea. Extraneous cruft that isn&#x27;t caught by .gitignore will leak into the repo. Always run git diff and git status first to see what you are about to add.
评论 #33804057 未加载
评论 #33804321 未加载
评论 #33804314 未加载
gabrielgio超过 2 年前
&gt; you need to re-clone from scratch — even if you did nothing wrong.<p>I don&#x27;t think you will need to reclone if did nothing wrong. You can always use `git reset --hard origin&#x2F;...`, and if that does not work the you definitely did something wrong.<p>&gt; But in Linus’s own words, Git is “the information manager from hell.”<p>That git is not the same git we have today, and it was handed over to another person quite early in the development. Although I agree that git ux is sometimes confusing.<p>&gt; Limit your Git actions ... for peak Git efficiency<p>I pretty much disagree, if I can give my two cents, read the manual. Git have some really handy tooling that can help with non-git issue (e.g.: `git bisect`). Limiting your knowledge brings no benefit.<p>I like some point of the text, but overall I don&#x27;t like the premise. it exaggerate a lot a problem to prove a point.
jangofett27超过 2 年前
I&#x27;ll always be a rebase diehard, but the core message here is great. If you have to do more than a little bit of git surgery, you&#x27;re probably doing something else wrong.
评论 #33804114 未加载
alkonaut超过 2 年前
Without rebasing, tools for managing PRs might show the merged mainline commits in the PR.<p>Some times they are described as such “merged master into feature” and can be avoided if you review the PR <i>per commit</i>. But more often I want to review the PR as a whole, and then the tool fails to show a good diff of what’s actually developed in the PR. This to me is a <i>much</i> larger problem than the log pollution, which can be solved by squashing.<p>Other than that (missing the bigger reason for rebase and focusing on a lesser argument in my opinion) I quite agree with the article.
everybodyknows超过 2 年前
Clicking through a self-link in the article <a href="https:&#x2F;&#x2F;blog.trunk.io&#x2F;git-commit-messages-are-useless-c2f3c46f678e" rel="nofollow">https:&#x2F;&#x2F;blog.trunk.io&#x2F;git-commit-messages-are-useless-c2f3c4...</a> we read:<p>&gt; This isn’t grade school, you don’t have to show your work As you become an efficient engineer, the path you took to get to the final state of a pull request becomes far less important — and is academically interesting at best. You shouldn’t have to show your work like you did in school. Land the feature or bug and move on to the next one. The code speaks for itself (alongside some judiciously placed comments).<p>&gt; Having granular annotations of all your work is unnecessary, ...<p>This premise underlies the particular workflow that the posted article assumes, and all the described command+option incantations are directed to it.<p>But there is another, very different git workflow used by a project we&#x27;ve all heard of, and that is the Linux kernel core code. The trunk.io workflow is unsuitable for Linux due to different requirements. Some of which being:<p>1. Commitment to support for indefinite future.<p>2. Large, complex feature PRs.<p>3. Human review of PRs, by maintainers fully empowered to reject.<p>4. A low-level programming language, in which subtle bugs are easily introduced.<p>Also different luxuries:<p>1. Willingness to put off merge of a &quot;hot&quot; new feature indefinitely.<p>So, kernel PRs are structured as a linear series of numbered patches meeting the requirement that each step along the way compile cleanly. This is primarily to ease the task of the maintainer responsible for the subsystem involved, and who will have deal with the fallout of bugs introduced by the PR. Example:<p><a href="https:&#x2F;&#x2F;lore.kernel.org&#x2F;rcu&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lore.kernel.org&#x2F;rcu&#x2F;</a><p>Credential: I have written code for the Linux kernel core, and it was merged, and it was buggy.
评论 #33810950 未加载
sossunday超过 2 年前
&gt; git push origin<p>&gt; Push my code to the remote; likely spinning up lots of machines in CI to check my work.<p>That&#x27;s a good callout; something that I have noticed I frequently miss when iterating on my code is the cost of the CI&#x2F;CD systems already set up. It&#x27;s something to consider especially when iterating using a system like Sapling for Stacked PRs; each individual PR push may update a chain which causes a lot of wasted CI&#x2F;CD time.
评论 #33804212 未加载
评论 #33803168 未加载
jbergknoff超过 2 年前
&gt; The easiest practice to implement for peak Git efficiency is to stick to a subset of commands<p>This has been my experience as well.<p>Great article, thanks! I&#x27;ve been using essentially this same subset of commands for many years, and it&#x27;s worked extremely well for me: does everything I need&#x2F;my team needs, and avoids complication. I&#x27;m glad to have this as a reference I can point people to when they ask for git advice.
bsima超过 2 年前
How does this guy run a developer tools company called “trunk” and yet doesn’t understand rebase? Talk about killing credibility…
评论 #33806895 未加载
surf_wreck21超过 2 年前
I agree; maybe when git was new and actually being used in a decentralized fashion some of the more advanced operations were necessary. But with the typical checkout&#x2F;branch&#x2F;PR&#x2F;merge flow from GitHub and others, I rarely need anything but git merge (with squash merging when merging a pr)
GMoromisato超过 2 年前
Nice! Maybe someone should create an opinionated git front-end to enforce some of these patterns on a team.<p>The irony, IMO, is that Linus prefers C to C++ exactly because C++ gives developers too much rope.
federicoweber超过 2 年前
I&#x27;m a huge fan of squash rebase, myself. really it&#x27;s my default, and I find it particularly useful for long run branches.
LocalPCGuy超过 2 年前
I personally am a proponent of rebase, but not all the time and not for every workflow. It has it&#x27;s place though, IMO. I like&#x2F;value clean history and good commit messages (although I admit I don&#x27;t always succeeding providing that all of the time). I prefer to stage my commit pieces at the hunk level at the largest. I like to rebase my branches before merging them into release or main (depending on git strategy as a whole), but it isn&#x27;t always necessary. I use interactive rebase from time to time to clean up my feature branches (especially longer running ones). This is all stuff I prefer in my own workflow.<p>That said, every time I try to really teach someone rebase, particularly a new dev, I understand why people shy away from it. I did for a very long time. So I totally understand and get why the above style workflow may terrify folks (or just seem unnecessary). It is easy to mess up and there are a lot of little gotchas if someone isn&#x27;t careful. And worst of all, it can result in lost work (although even that is &quot;usually&quot; recoverable, but not always). I do think there are some benefits to it, and I think it is something that can be integrated into a dev&#x27;s workflow a bit at a time. And it really doesn&#x27;t take significantly more time, in my experience.<p>I&#x27;m not gonna argue here for adopting that. Except for &quot;no commit messages&quot;, I&#x27;d be pretty ok with a workflow as outlined by this post. I do think folks should understand how rebase works, what commits will be moved&#x2F;changed when they run a rebase (this is vital), and how to recover when a rebase goes bad (no, not reclone, not generally even delete branch and check it out again).<p>.<p>Couple random thoughts I try to communicate to folks who decide to utilize rebase more in their workflow:<p>- rebase often (if main updates often)<p>- if worried the rebase may be messy, create a temporary branch prior to starting the rebase at the feature branch HEAD - allows for an easy way back (and prevents lost code)<p>- don&#x27;t rebase shared branches - this is a tool to use PRIOR to &quot;sharing&quot; (i.e. pushing) code<p>- squash&#x2F;clean up unneeded commits before rebasing on another branch (this may bring it all the way down to a single commit, but for larger features, I think there is value in seeing the main decision points along the way)<p>- fix conflicts with the code at the specific commit you are on only, don&#x27;t fix it with the eventual end result X commits down the line - this will generally avoid the dreaded &quot;fix the same conflict over and over for each commit&quot; problem some people encounter with rebasing<p>- remember rebase creates new history - it doesn&#x27;t rewrite history (however, old commits will eventually be garbage collected)<p>- pro tip: understand how `rebase --onto` works, sometimes you shouldn&#x27;t, or at least don&#x27;t want to, take all of the commits