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


当前回答

Use:

git reset HEAD filepath

例如:

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

其他回答

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

您可以执行以下两条命令:

# Revert changes to modified files.
git reset --hard

# Remove all untracked files and directories.
# '-f' is force, '-d' is remove directories.
git clean -fd

从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

一个不平凡的方法是运行这两个命令:

这将移动您的更改到stash,将您带回HEAD状态 这将删除在上一个命令中创建的最新的stash。