Git撤消命令:"git reset --hard"; [英] Git undo command: "git reset --hard"

查看:133
本文介绍了Git撤消命令:"git reset --hard";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在intelliJ中从事Java项目.我输入以下命令:在终端中输入"git reset --hard".如何撤消该命令?在执行此命令之前,我没有提交任何内容.现在一切都丢失了吗?

Im working on a Java project in intelliJ. I typed in the following command: "git reset --hard" in the terminal. How do I undo this command? Before this command I didnt commit anything. Is everything lost now?

推荐答案

有3种可能性:

  • 您的IDE具有检索已删除文件的功能. Intellij(以及JetBrains的所有IDE)都具有此功能.诸如VSCode,Atom等的编辑器都具有可以做到这一点的扩展.

  • Your IDE has a feature to retrieve deleted file. Intellij (and all IDE by JetBrains) has this feature. Editors like VSCode, Atom, ... have extensions that could do that.

在进行重置之前,您已经暂存了文件(执行git add),因此git可以帮助您检索一些文件.参见在Git,如何恢复提交之前已还原的暂存文件? https://edwardthomson.com/blog/introducing_git_recover.html (从那时起,我创建了git命令行来帮助恢复暂存的文件.请参见

You already have staged your files (doing a git add) before doing the reset, so git could help you retrieve some files. See In Git, how can I recover a staged file that was reverted prior to committing? and https://edwardthomson.com/blog/introducing_git_recover.html (edit: I have since then created a git command line to help recover staged files. See https://stackoverflow.com/a/58853981/717372)

您没有暂存文件,因此从git的角度来看,所有文件都丢失了:(您仍然可以尝试使用文件恢复工具.

You didn't staged files, so all your files are lost from a git point of view :( You could still try to use a file recovery tool.

PS: 但是,在使用git "时,请不要忘记最重要的规则之一,并且经常进行所有操作(尤其是在做一些您不掌握的事情之前).您将始终能够检索您的更改/提交(至少使用reflog)"

PS: But don't forget one of the most important rule when using git "Commit everything and often (and especially before doing things you don't master). You will always be able to retrieve your changes/commits (at least using the reflog)"

这篇关于Git撤消命令:"git reset --hard";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆