Git:如何覆盖本地更改?
我使用 github 上的 git clone 并删除了一些文件&修改了一些文件。现在我想保留我的本地代码&恢复到原来的形式。有没有命令可以实现这个目的?
I use git clone from github and I deleted some files & modified some files. Now I want to keep my local code & restore to the original form. Is there a command to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想先保存更改,您可以先提交它们,然后将代码签出到以前的提交:
git checkout HEAD^
(一次提交)git checkout GEAD~2
(2 次提交)或者,如果您不再需要更改,请运行
git reset --hard HEAD
If you want to save you changes first, you can commit them before and then checkout you code to previous commit(s):
git checkout HEAD^
(one commit back)git checkout GEAD~2
(2 commits back)Or, if you don't need your changes anymore, run
git reset --hard HEAD
git checkout
如果您想签出整个存储库,请从根目录使用
git checkout 。
git checkout <name of file>
If you want to check out the whole repository, then from the root directory use
git checkout .
git重置--hard
git reset --hard
Git 命令通过覆盖所有本地更改来从分支中提取所有更改:-
Git command to pull all changes from branch by overwriting all local changes:-
您可以通过此命令删除本地更改
并通过以下方式拉取更改:
You can remove local changes by this command
and pull changes by: