Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
将您的最后一个 git 提交移回“未暂存的更改”+“未跟踪的文件”区域的最佳方法是什么(有问题的提交未推送/仅在您的本地存储库中,有效地将其从 HEAD 中删除)?
换句话说,您如何回滚提交,但自动将该差异应用到您的未暂存区域?
您可以使用git reset将当前分支设置为先前的提交,即HEAD^
git reset
HEAD^
git reset HEAD^
添加--soft会将这些文件保留在索引中:(准备提交)
--soft
git reset --soft HEAD^
--soft (...) 这会留下所有更改的文件“要提交的更改”,就像 git status 所说的那样。
(...) 这会留下所有更改的文件“要提交的更改”,就像 git status 所说的那样。
git-extras提供了一个git undo命令,它更容易记住做同样事情的方式(以及许多其他方便的附加功能,顾名思义)。
git undo