Git:如何覆盖本地更改?

发布于 2024-09-30 02:11:11 字数 92 浏览 8 评论 0原文

我使用 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 技术交流群。

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

发布评论

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

评论(5

方圜几里 2024-10-07 02:11:11

如果您想先保存更改,您可以先提交它们,然后将代码签出到以前的提交:
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

怪我入戏太深 2024-10-07 02:11:11

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 .

鲸落 2024-10-07 02:11:11

git重置--hard

git reset --hard

水晶透心 2024-10-07 02:11:11

Git 命令通过覆盖所有本地更改来从分支中提取所有更改:-

git reset --hard HEAD
git pull

Git command to pull all changes from branch by overwriting all local changes:-

git reset --hard HEAD
git pull
不及他 2024-10-07 02:11:11

您可以通过此命令删除本地更改

git clean -f

并通过以下方式拉取更改:

git pull

You can remove local changes by this command

git clean -f

and pull changes by:

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