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.

Gitjk – command to undo what you just did in git

83 pointsby mapmeldalmost 11 years ago

15 comments

_kst_almost 11 years ago
If you name it &quot;git-jk&quot; rather than &quot;gitjk&quot;, you can invoke it as<p><pre><code> git jk</code></pre>
评论 #7801958 未加载
评论 #7801718 未加载
评论 #7801537 未加载
jamesgeck0almost 11 years ago
I occasionally wish git had an undo-whatever-I-just-did command, and I&#x27;ve been using it for years.<p>The git fixup page comes in quite handy. <a href="https://sethrobertson.github.io/GitFixUm/fixup.html" rel="nofollow">https:&#x2F;&#x2F;sethrobertson.github.io&#x2F;GitFixUm&#x2F;fixup.html</a>
tethaalmost 11 years ago
Why is sudo hardcoded into so many commands? I&#x27;ll run your program with privileges if it needs and earned them, thank you very much.
评论 #7801379 未加载
评论 #7801401 未加载
bilalqalmost 11 years ago
It&#x27;s kind of nice that this just gives suggestions by default rather than running potentially breaking commands.<p>But as someone else here mentioned, you really want to understand the reflog in git. Everyone screws up at some point or another, and it&#x27;s much easier to work through things when you can rely on the reflog to act as a safety net and an anchor of sanity.
pathikritalmost 11 years ago
Adding it here: <a href="http://stackoverflow.com/questions/12589813/whats-a-single-git-command-to-unbork-myself" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;12589813&#x2F;whats-a-single-g...</a>
prezjordanalmost 11 years ago
The git reflog gets you out of all kinds of messes. <a href="https://medium.com/git-tips/a4189dd88c40" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;git-tips&#x2F;a4189dd88c40</a>
tjdetwileralmost 11 years ago
I&#x27;m pretty sure your fetch logic is not right. First it assumes no arguments are passed. You assume origin&#x2F;master (which is convention but not guaranteed) and also you assume a refspec isn&#x27;t passed (in which case you need to rollback FETCH_HEAD).
junkblockeralmost 11 years ago
See also<p><a href="http://blog.kazuhooku.com/2014/04/announcing-unco-undo-changes-to-files.html" rel="nofollow">http:&#x2F;&#x2F;blog.kazuhooku.com&#x2F;2014&#x2F;04&#x2F;announcing-unco-undo-chang...</a>
lunixbochsalmost 11 years ago
If anyone wants a fish function:<p><pre><code> function jk history | head -n+10 | tail -r | gitjk_cmd end </code></pre> Maybe git full undo via automatic snapshotting (branch&#x2F;stash)? It&#x27;s fine unless you hit a perf wall on huge repos.
thrushalmost 11 years ago
Does it work if you call it 2x or more?
burkealmost 11 years ago
rebase isn&#x27;t very hard to implement; you just have to check the reflog.
homulillyalmost 11 years ago
Uh... if you want to undo a git add shouldn&#x27;t you be doing git reset?
评论 #7801422 未加载
svckralmost 11 years ago
Isn&#x27;t that what git reflog + reset are for?
develop7almost 11 years ago
It does rely on history? Well, it won&#x27;t work for me then — in my history there&#x27;s only frequently-used commands.
lazzlazzlazzalmost 11 years ago
sudo hard-coded, and an intolerably stupid name. Next.
评论 #7801399 未加载