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.

How to undo almost anything with Git (2015)

372 pointsby ljiljanaover 5 years ago

17 comments

nneonneoover 5 years ago
Also worth noting: you can abort and undo many kinds of in-progress operations with “git &lt;operation&gt; —abort”. Works for merge, rebase, and a few other things, and can seriously save your bacon when you do a “git merge &lt;badbranch&gt;” and are suddenly confronted with a bazillion merge conflicts.<p>Also, if you’re in a panic because something went screwy, check “git status” and read every line carefully. status tells you a lot more than you might expect - what branch you’re on, if you’re even on a branch, what merge&#x2F;rebase&#x2F;commit operation you’re in the middle of (if any), and even how to go forward with or back out of the current operation.<p>Finally, commit regularly and often! reflog and rebase mean that you can always maintain a clean history if you want, while committing makes sure that your changes are properly tracked and saved by git so you can rewind when needed. Once you get comfortable with it, git lets you really practice fearless experimentation, which unlocked a whole new level of productivity for me.
评论 #21870759 未加载
评论 #21872036 未加载
评论 #21871169 未加载
onekorgover 5 years ago
The thing that made git click for me was to understand the data structures that make git work.<p>There&#x27;s beauty and elegance in the implementation details of git. You can do and undo with confidence once you can translate the changes you want to make to git object transformations.<p>To get an overview of the concepts behind git I recommend this article by one of the GitHub founders: <a href="http:&#x2F;&#x2F;tom.preston-werner.com&#x2F;2009&#x2F;05&#x2F;19&#x2F;the-git-parable.html" rel="nofollow">http:&#x2F;&#x2F;tom.preston-werner.com&#x2F;2009&#x2F;05&#x2F;19&#x2F;the-git-parable.htm...</a><p>To understand the data structures I suggest: <a href="https:&#x2F;&#x2F;codewords.recurse.com&#x2F;issues&#x2F;two&#x2F;git-from-the-inside-out" rel="nofollow">https:&#x2F;&#x2F;codewords.recurse.com&#x2F;issues&#x2F;two&#x2F;git-from-the-inside...</a>
评论 #21870628 未加载
评论 #21871742 未加载
评论 #21870863 未加载
godotover 5 years ago
I&#x27;m actually somewhat surprised that this wasn&#x27;t mentioned in the comments yet: <a href="https:&#x2F;&#x2F;ohshitgit.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ohshitgit.com&#x2F;</a> Which is a page that covers common mistakes using git and quick ways to fix your mistakes. I&#x27;ve found myself making a mistake mentioned on this page with regularity and always refer to the site to help myself fix it quickly.<p>(It looks like they have a swearing-safe version now at <a href="https:&#x2F;&#x2F;dangitgit.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dangitgit.com&#x2F;</a>)
评论 #21870160 未加载
3pt14159over 5 years ago
It has always bugged me that<p><pre><code> git commit --amend </code></pre> Doesn&#x27;t automatically resign (or fail to resign if the key isn&#x27;t available) a signed git commit message. Anytime there is a non-verified git commit message in my history you can be sure it&#x27;s because I was a dummy on the original message.
评论 #21868437 未加载
kbensonover 5 years ago
This flowchart[1] has been useful to me a few times when I&#x27;ve been lost on how to fix something. I usually keep it as a bookmark, but I don&#x27;t have it saved on this computer, so I just did a google image search and was able to fine it fairly quickly. A google image search for &quot;git solution workflow&quot; or &quot;git fix flowchart&quot; finds it right away, in case this tickles your brain in the future and you want to find it again, and vaguely remember it&#x27;s easy to find through image search.<p>Edit: Updated the link to go to the site referenced in the image. Might as well send you to who developed it so they get some credit.<p>1: <a href="http:&#x2F;&#x2F;justinhileman.info&#x2F;article&#x2F;git-pretty&#x2F;" rel="nofollow">http:&#x2F;&#x2F;justinhileman.info&#x2F;article&#x2F;git-pretty&#x2F;</a>
评论 #21870301 未加载
RickJWagnerover 5 years ago
Git is one of those once-a-decade technologies that&#x27;s compicated, user un-friendly, takes months to master and is absolutely worth it.
评论 #21870039 未加载
评论 #21869892 未加载
评论 #21869167 未加载
deftover 5 years ago
This page is from 2015 yet hasn&#x27;t once came up on my searches to do a bunch of these things. Thanks for resharing.
dangover 5 years ago
Discussed at the time: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9679367" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9679367</a>
评论 #21868077 未加载
chxover 5 years ago
Except you can&#x27;t undo git reset --hard unless of course you build a safety net. <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;chx&#x2F;3a694c2a077451e3d446f85546bb9278" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;chx&#x2F;3a694c2a077451e3d446f85546bb9278</a>
sabootover 5 years ago
For several months now I&#x27;ve been wondering how to get rid of a 700 MB data file that was accidentally committed to our shared git repo. Now everyone has it, and a clean pull takes forever. Appreciate any thoughts.
评论 #21869817 未加载
评论 #21871168 未加载
sadness2over 5 years ago
Not reading. Nothing is ever as good as this flow chart: <a href="http:&#x2F;&#x2F;sethrobertson.github.io&#x2F;GitFixUm&#x2F;fixup.html" rel="nofollow">http:&#x2F;&#x2F;sethrobertson.github.io&#x2F;GitFixUm&#x2F;fixup.html</a>
SlowRobotAheadover 5 years ago
&gt; You started a new branch feature based on master, but master was pretty far behind origin&#x2F;master<p>I’m bad at git. So... wait what now?<p>When is Master not Origin&#x2F;Master? I don’t understand what is going on there. Explain?
评论 #21869994 未加载
评论 #21870002 未加载
juliangambleover 5 years ago
It&#x27;s missing git revert merges<p><pre><code> git revert -m 1 88113a64a21bf8a51409ee2a1321442fd08db705</code></pre>
评论 #21868224 未加载
ameliusover 5 years ago
But can it also undo the undo?<p>Anyway, shouldn&#x27;t git just come with a &quot;undo&quot; command?
评论 #21871041 未加载
jlduggerover 5 years ago
git-extras has a tool called `git undo`. It&#x27;s just a fancy wrapper around `git reset --soft HEAD` though.
评论 #21871095 未加载
crazypythonover 5 years ago
I use GitUp.
m4r35n357over 5 years ago
TLDR: Reflog. That is all.