重置 git 中上次提交后的所有更改
如何撤消上次提交后对目录所做的每项更改,包括删除添加的文件、重置修改的文件以及添加回已删除的文件?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,重置所有更改
这将撤消您对跟踪文件所做的任何更改并恢复已删除的文件:
其次,删除新文件
这将删除添加的所有新文件自上次提交以来:
由于
.gitignore
而未跟踪的文件将被保留;它们不会被删除警告:使用
-x
而不是-fd
会删除被忽略的文件。您可能不想这样做。First, reset any changes
This will undo any changes you've made to tracked files and restore deleted files:
Second, remove new files
This will delete any new files that were added since the last commit:
Files that are not tracked due to
.gitignore
are preserved; they will not be removedWarning: using
-x
instead of-fd
would delete ignored files. You probably don't want to do this.您可以通过以下方式撤消对跟踪文件的更改:
您可以通过以下方式删除未跟踪文件:
您可以通过以下方式删除未跟踪文件和目录:
但是您无法撤消对未跟踪文件的更改。
您可以删除被忽略和未跟踪的文件和目录
但是您无法撤消对忽略文件的更改。
您还可以将
clean.requireForce
设置为false
:以避免使用
-f
(--force
)使用 git clean 。You can undo changes to tracked files with:
You can remove untracked files with:
You can remove untracked files and directories with:
but you can't undo change to untracked files.
You can remove ignored and untracked files and directories
but you can't undo change to ignored files.
You can also set
clean.requireForce
tofalse
:to avoid using
-f
(--force
) when you usegit clean
.有两个命令可以在这种情况下工作,
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