Home  >  Q&A  >  body text

java - git上面,工作目录怎么恢复到上次提交的版本

所有命令都还没有push。
由于在编辑某文件的过程中不小心做了改动,然后点了保存,还没有commit。
想要利用git恢复成尚未改动时的样子。
下面是问题描述:
我在git上创建了一个名为“428”的分支,也知道上一次提交的版本。
下面是各分支的情况

试过了下面的命令了

git checkout -- 

但是本地目录中的文件还是未恢复,应该怎么操作?

补充:虚拟环境目录下的文件夹也会随着git命令改动吗?

大家讲道理大家讲道理2730 days ago477

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 17:57:05

    git reset --hard <commmit hash>

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:57:05

    To restore a single file, use git checkout [previously submitted commit id] -- file name. If you want to discard all files in the workspace, use git reset --hard <commit id>

    reply
    0
  • 阿神

    阿神2017-04-17 17:57:05

    git reset HEAD^
    Revert the last commit, so that the commit is rolled back and the changes will be retained in the uncommitted state

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:57:05

    git checkout -- You need to specify the file name later.
    If you want to undo all the uncommitted changes in your working directory, you can use git stash. This is to temporarily undo the changes and save them if you no longer need to restore them. , git stash drop will never recover.

    reply
    0
  • Cancelreply