重置 git 中上次提交后的所有更改

发布于 2024-10-11 02:55:40 字数 56 浏览 0 评论 0原文

如何撤消上次提交后对目录所做的每项更改,包括删除添加的文件、重置修改的文件以及添加回已删除的文件?

How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沙沙粒小 2024-10-18 02:55:40

首先,重置所有更改

这将撤消您对跟踪文件所做的任何更改并恢复已删除的文件:

git reset HEAD --hard

其次,删除新文件

这将删除添加的所有新文件自上次提交以来:

git clean -fd

由于 .gitignore 而未跟踪的文件将被保留;它们不会被删除

警告:使用-x而不是-fd删除被忽略的文件。您可能不想这样做。

First, reset any changes

This will undo any changes you've made to tracked files and restore deleted files:

git reset HEAD --hard

Second, remove new files

This will delete any new files that were added since the last commit:

git clean -fd

Files that are not tracked due to .gitignore are preserved; they will not be removed

Warning: using -x instead of -fd would delete ignored files. You probably don't want to do this.

烟─花易冷 2024-10-18 02:55:40

如何撤消上次提交后对目录所做的所有更改,包括删除添加的文件、重置修改的文件以及添加回已删除的文件?

  1. 您可以通过以下方式撤消对跟踪文件的更改:

    git reset HEAD --hard
    
  2. 您可以通过以下方式删除未跟踪文件:

    git clean -f
    
  3. 您可以通过以下方式删除未跟踪文件和目录:

    git clean -fd
    

    但是您无法撤消对未跟踪文件的更改

  4. 您可以删除被忽略和未跟踪的文件和目录

    git clean -fdx
    

    但是您无法撤消对忽略文件的更改

您还可以将 clean.requireForce 设置为 false

git config --global --add clean.requireForce false

以避免使用 -f (--force)使用 git clean 。

How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?

  1. You can undo changes to tracked files with:

    git reset HEAD --hard
    
  2. You can remove untracked files with:

    git clean -f
    
  3. You can remove untracked files and directories with:

    git clean -fd
    

    but you can't undo change to untracked files.

  4. You can remove ignored and untracked files and directories

    git clean -fdx
    

    but you can't undo change to ignored files.

You can also set clean.requireForce to false:

git config --global --add clean.requireForce false

to avoid using -f (--force) when you use git clean.

耳钉梦 2024-10-18 02:55:40

有两个命令可以在这种情况下工作,

root>git reset --hard HEAD~1

root>git push -f

有关更多 git 命令,请参阅此 页面

There are two commands which will work in this situation,

root>git reset --hard HEAD~1

root>git push -f

For more git commands refer this page

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文