是否有一个Git命令可以恢复工作树和索引中所有未提交的更改,并删除新创建的文件和文件夹?


当前回答

从Git帮助:

 Changes to be committed:
      (use "git restore --staged <file>..." to unstage)

    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)

其他回答

Use:

git reset HEAD filepath

例如:

git reset HEAD om211/src/META-INF/persistence.xml

请注意,可能仍然有文件看起来不会消失——它们可能是未编辑的,但Git可能因为CRLF / LF更改而将它们标记为正在编辑。看看你最近是否在.gitattributes中做了一些更改。

在我的例子中,我将CRLF设置添加到.gitattributes文件中,因此所有文件都保留在“修改文件”列表中。更改.gitattributes设置会使它们消失。

我认为你可以使用以下命令:git reset——hard

我通常使用这种方法,效果很好:

mv fold/file /tmp
git checkout fold/file

安全而漫长的路:

Git分支要删除 Git签出删除 Git添加。 “我做了件坏事,对不起” Git检查开发 git分支-D删除