This commit is contained in:
Cat Tom 2024-07-25 02:53:51 +08:00
parent a0c7accc02
commit 90ccd85f7c
3 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,27 @@
# Git: 覆盖本地修改
!!! warning "注意!"
本文介绍的命令将使你放弃所有本地更改,而使用远程分支中的副本重置/覆盖所有内容。
输入以下命令来覆盖本地文件:
```sh
git fetch --all
git reset --hard <remote>/<branch_name>
```
例如:
```sh
git fetch --all
git reset --hard origin/main
```
> 不论是否使用 --hard 选项,所有尚未推送的本地提交都将丢失。
## 命令详解
`git fetch` 从远程下载最新版本,不会尝试合并或重新设置任何内容。
然后 `git reset` 将 main 分支重置为你刚获取的分支。--hard 选项更改工作树中的所有文件,以匹配 origin/main 中的文件。

View File

@ -1,4 +1,4 @@
# 技术 # 技术
> 路漫漫其修远兮,吾将上下而求索。 > 路漫漫其修远兮,吾将上下而求索。
> >
> ——《离骚》 > 《离骚》

View File

@ -77,6 +77,7 @@ nav:
- "标签": blog/tags.md - "标签": blog/tags.md
- "技术": - "技术":
- tech/index.md - tech/index.md
- "Git: 覆盖本地修改": tech/Git-overwriting-local-changes.md
- "手把手教你备份和还原 Docker 卷": tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md - "手把手教你备份和还原 Docker 卷": tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md
- "创建和管理 Linux 服务器用于身份验证的 SSH 密钥": tech/Creating-and-Managing-SSH-Keys-for-Authentication-on-Linux-Servers.md - "创建和管理 Linux 服务器用于身份验证的 SSH 密钥": tech/Creating-and-Managing-SSH-Keys-for-Authentication-on-Linux-Servers.md
- "MkDocs 参考": examples/index.md - "MkDocs 参考": examples/index.md