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.

Git reset vs. Git revert

54 pointsby github-catover 6 years ago

7 comments

amingilaniover 6 years ago
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 未加载
cataflamover 6 years ago
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__over 6 years ago
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.
emeralddover 6 years ago
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 未加载
dabitudeover 6 years ago
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).
jancsikaover 6 years ago
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.)
danielhlockardover 6 years ago
Why is this linked to the comment section?
评论 #19082760 未加载