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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Git reset vs. Git revert

54 点作者 github-cat超过 6 年前

7 条评论

amingilani超过 6 年前
I always use a soft reset when I accidentally commit in the wrong order, because I like keeping my history tidy. If the change is live, I always use revert.<p>On another note, I love how HN can go from complex research papers I struggle to keep up with, to explaining git commands the next day — something I learned within my first month of Git and never had a problem with again. How bipolar.
评论 #19082676 未加载
cataflam超过 6 年前
The explanation that made me understand git reset the best is &quot;Git Tools – Reset Demystified&quot; from the Pro Git book [0].<p>Everything has been crystal clear since. I highly recommend it if you use git.<p>[0] <a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Tools-Reset-Demystified" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Tools-Reset-Demystified</a>
__david__超过 6 年前
I think the main thing is, if you&#x27;ve already pushed to somewhere where others will pull from then use revert. Otherwise, use rebase (or reset+cherry-pick or amend, etc). If you push a patchset that has a patch and also a revert patch for that patch then you&#x27;re just adding completely unnecessary noise for anyone who is reviewing the patches.
emeraldd超过 6 年前
The chunk about `git reset --hard` should be prefixed with a big warning label saying &quot;Don&#x27;t use this unless you know exactly what you&#x27;re doing&quot;. There are very few legitimate reasons to use `git reset --hard &lt;commit&gt;` in the way that the article describes and even fewer if you&#x27;re working with remote. Now `git reset` (No commit or --hard) can be useful to retry a screwed staging, but that&#x27;s about it. As to squashing commits... that&#x27;s a whole different set of problems when you&#x27;re dealing with auditors and code review requirements and &quot;public&quot; commits.
评论 #19082982 未加载
评论 #19082996 未加载
dabitude超过 6 年前
This is a pretty bad article.<p>In the last example (which is actually the most common case in practice), they give wrong instructions. They should only revert the bad commit, not all the following commits. Reverting everything is impractical and useless, and if you want to do that you may as well use revert (which is still a bad idea).
jancsika超过 6 年前
I love how the illustrations are actually the obvious default interface that everyone should be using to edit nodes in a graph. Click &quot;Delete&quot; while the box is around C and D: done. (Or right clicking and choosing &quot;commit a reversion&quot; or whatever.)
danielhlockard超过 6 年前
Why is this linked to the comment section?
评论 #19082760 未加载