是否有一个Git命令可以恢复工作树和索引中所有未提交的更改,并删除新创建的文件和文件夹?
当前回答
安全而漫长的路:
Git分支要删除 Git签出删除 Git添加。 “我做了件坏事,对不起” Git检查开发 git分支-D删除
其他回答
使用“git checkout——…”来丢弃工作目录中的更改
git checkout -- app/views/posts/index.html.erb
or
git checkout -- *
删除在git状态下对非暂存文件所做的所有更改
modified: app/controllers/posts.rb
modified: app/views/posts/index.html.erb
如果您只想还原当前工作目录中的更改,请使用
git checkout -- .
在此之前,你可以列出将被恢复的文件,而不实际做任何操作,只是检查将会发生什么,用:
git checkout --
Use:
git reset HEAD filepath
例如:
git reset HEAD om211/src/META-INF/persistence.xml
我通常使用这种方法,效果很好:
mv fold/file /tmp
git checkout fold/file
你可以使用下面的Git命令,它可以恢复你仓库中所有未提交的更改:
git checkout .
例子:
ABC@ABC-PC MINGW64 /c/xampp/htdocs/pod_admin (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: application/controllers/Drivers.php
modified: application/views/drivers/add.php
modified: application/views/drivers/load_driver_info.php
modified: uploads/drivers/drivers.xlsx
no changes added to commit (use "git add" and/or "git commit -a")
ABC@ABC-PC MINGW64 /c/xampp/htdocs/pod_admin (master)
$ git checkout .
ABC@ABC-PC MINGW64 /c/xampp/htdocs/pod_admin (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean