git恢复初始状态
6 2026-02-10 11:59 2026-02-10 11:59
问:
Administrator@PC-202312022041 MINGW64 ~/AppData/Local/nvim (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: lua/mappings.lua
Untracked files:
(use "git add <file>..." to include in what will be committed)
lazy-lock.json
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@PC-202312022041 MINGW64 ~/AppData/Local/nvim (main)
$
我想让当前目录下的git status异常的项目完全恢复初始状态
答:
我来帮你恢复 Git 仓库到初始状态。根据你的
git status
恢复步骤
1. 撤销已修改的文件(modified)
git restore lua/mappings.lua
2. 删除未跟踪的文件(untracked)
rm lazy-lock.json
.gitignore
一键恢复所有(更彻底的方法)
# 重置所有已跟踪的文件
git reset --hard HEAD
# 清理所有未跟踪的文件和目录(危险,会真的删除文件!)
git clean -fd
⚠️ 警告:plain
会永久删除所有未跟踪的文件,无法恢复!复制git clean -fd
推荐的安全做法
# 1. 先查看会被删除哪些文件(预览模式)
git clean -n
# 2. 确认无误后,执行清理
git clean -fd
# 3. 重置已修改的文件
git reset --hard HEAD
git status
nothing to commit, working tree clean
全部评论