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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How to undo almost anything with Git

411 点作者 agonzalezro将近 10 年前

15 条评论

npongratz将近 10 年前
I&#x27;ve used the following flow chart to help determine strategies to get myself out of messes:<p><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><p>Just another way of presenting similar information. No affiliation, just a satisfied consumer of the info :)
评论 #9683376 未加载
评论 #9683708 未加载
mmanfrin将近 10 年前
My only real git crisis was when I accidentally `git push -f`ed what I thought was my own branch, but actually the `develop` branch. On a monday. After a weekend where about a hundred commits had been cherry picked and merged in to develop by a dev not in the office. None of my coworkers had recent versions of develop.<p>The thing that ended up saving me was our CI -- we autodeployed passing builds to our staging env; so we were able to ssh in and `git push -f` back from staging to our repo.
评论 #9681918 未加载
评论 #9683975 未加载
评论 #9682381 未加载
评论 #9681951 未加载
评论 #9682044 未加载
评论 #9684607 未加载
评论 #9681908 未加载
评论 #9684748 未加载
评论 #9684197 未加载
johnnymonster将近 10 年前
This does not cover the only scenario which I was hoping it would. I accidentally pushed my api key&#x2F;password to github and I want to &quot;undo&quot; that push and completely remove the history locally and on an origin? This is so obscure across many different outlets. And go ahead, flame me for pushing my password&#x2F;api key to github, but all of you know you have done this at least once in your life!
评论 #9683595 未加载
评论 #9682283 未加载
评论 #9682530 未加载
评论 #9684293 未加载
评论 #9682509 未加载
js2将近 10 年前
Was this taken from <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9661349" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9661349</a> or is it just a coincidence?
forrestthewoods将近 10 年前
I&#x27;m so glad I use Perforce. Yeah branches are a bit cumbersome. But it&#x27;s idiot proof. There is literally no way for any artist to cause irreversible harm. They can&#x27;t even do harm that isn&#x27;t easy to fix with a few clicks in an easy to use, easy to understand, easy to discover GUI.<p>I suppose one of the key features of Git is the ability to rewrite history. It makes a lot of sense in the context of an open source project pulling in changes from the wild. For most of us such utilities aren&#x27;t just useless they&#x27;re actively harmful.<p>Never leave me P4. Please God never leave me.
评论 #9684098 未加载
评论 #9684615 未加载
评论 #9684684 未加载
thyrsus将近 10 年前
Something I&#x27;m still working out....<p>I have a directory tree full of test data. As the project goes along, the test data will evolve, and thus should go under revision control.<p>Testing needs to start with known files, so, hey!, git checkout test_data - except that means my latest code revisions need to go into the test_data branch even before they&#x27;re tested :-(.<p>Then the tests make their changes to the data, which the tests check, and which I then want to throw away. So: &quot;git checkout test_data -f; git clean -f&quot; -- except that cleans out the source code area as well as the test data area.<p>I&#x27;m thinking the test data should be separate repository. Is that a mistake?<p>[Edit] I&#x27;ve tried looking at stackoverflow.com, but searching for &quot;git testing&quot; returned ~7000 articles, the first few hundred of which didn&#x27;t look relevant.
评论 #9682087 未加载
评论 #9682506 未加载
评论 #9682082 未加载
评论 #9682168 未加载
评论 #9682649 未加载
alphydan将近 10 年前
until this happens: <a href="http:&#x2F;&#x2F;renooble.tumblr.com&#x2F;post&#x2F;18845123629&#x2F;git-funny-scary-story" rel="nofollow">http:&#x2F;&#x2F;renooble.tumblr.com&#x2F;post&#x2F;18845123629&#x2F;git-funny-scary-...</a>
crimsonalucard将近 10 年前
as great as git is, I wish there was something more intuitive. Git is definitely one of the more confusing tools out there.
评论 #9682822 未加载
评论 #9684226 未加载
评论 #9682403 未加载
评论 #9684622 未加载
chx将近 10 年前
Though I walk through the valley of the shadow of rebase, I will fear no evil: for reflog are with me (sorry, couldn&#x27;t resist)
daxelrod将近 10 年前
See also <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> which has helped me immensely in the past.
nbouscal将近 10 年前
This is pretty good, I had never seen autosquash before. Another rebase flag that I find useful is --onto. For example, to rebase only the most recent N commits of a branch onto master:<p>git rebase HEAD~N --onto master
chriscool将近 10 年前
Instead of &quot;git reset --hard stuff&quot;, I recommend &quot;git reset --keep stuff&quot; as it will not delete uncommited files in the working directory.
评论 #9682800 未加载
ocdtrekkie将近 10 年前
This is pretty useful for Git noobs like me.
jokoon将近 10 年前
git checkout is what I want to do most of the time, but I always have been confused with svn checkout, so I never could remember it.
vacri将近 10 年前
One particularly tricky thing that this page doesn&#x27;t mention is removing binary blobs (or any file) from the history. Someone committed tens of megabytes of binary stuff to one of our repos. A later commit &#x27;fixed&#x27; this by removing them. But those binary blobs are still there, because it&#x27;s a historical commit, meaning every time you clone the repo (or similar) you get huge amounts of crap.<p>Maybe --squash will fix it? Something to look at, I guess.
评论 #9684531 未加载