Git 删除远程文件,并不再同步
上传时无意将Django项目中的db.sqlite3文件上传了。 需要按照以下步骤处理:
- 从暂存区(索引)中移除文件,但工作区的文件还保留着
git rm --cached ./proj/db.sqlite3- 确认文件状态,会看到该文件被标记为 "deleted"(在暂存区),同时被标记为 "untracked"(在工作区)
git status
# 显示输出
# On branch master
# Your branch is up to date with 'origin/master'.
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
# deleted: proj/db.sqlite3- 提交这次删除操作。从此,Git 不再追踪这个文件,但你的本地文件还在。
git commit -m "remove db.sqlite3"- 重要!将该文件放入.gitignore
# db.sqlite3
db.sqlite3