正在删除 Git 存储库中的文件但文件不存在
Removing a file in Git repo but file doesn't exist
在提交和推送到我的存储库时,出现以下错误:
问题是我已经手动删除了视频文件。该视频在我的仓库中不存在。
我也试过
git rm src/assets/video/Greensleeves
上面写着 fatal: pathspec src/assets/video/Greensleeves did not match any files
.
我怎样才能通过这个考试才能commit/push?
尝试并应用 new git filter-repo
, which does replace the old git filter-branch
or BFG。
它有 many usage examples,包括 path-based 过滤,以便您在过去的提交中远程 src/assets/video/Greensleeves
文件:
To keep all files except these paths, just add --invert-paths
:
git filter-repo --path src/assets/video/Greensleeves --invert-paths
然后 git push --force
(这确实会重写您存储库的历史记录,因此请务必通知任何其他协作者)
因为必须在新克隆上完成:
- 不要对您当前的克隆文件夹进行任何操作
- 创建存储库的单独克隆,在其中执行过滤器存储库
- 在第二个克隆中,现在已清理(历史上不再有大文件),从您的第一个存储库导入您的工作
即对于第3点:
cd /path/to/second/clone
git --work-tree=/path/to/first/original/clone add .
git commit -m "Import work from first clone"
git push --force
在提交和推送到我的存储库时,出现以下错误:
问题是我已经手动删除了视频文件。该视频在我的仓库中不存在。
我也试过
git rm src/assets/video/Greensleeves
上面写着 fatal: pathspec src/assets/video/Greensleeves did not match any files
.
我怎样才能通过这个考试才能commit/push?
尝试并应用 new git filter-repo
, which does replace the old git filter-branch
or BFG。
它有 many usage examples,包括 path-based 过滤,以便您在过去的提交中远程 src/assets/video/Greensleeves
文件:
To keep all files except these paths, just add
--invert-paths
:git filter-repo --path src/assets/video/Greensleeves --invert-paths
然后 git push --force
(这确实会重写您存储库的历史记录,因此请务必通知任何其他协作者)
因为必须在新克隆上完成:
- 不要对您当前的克隆文件夹进行任何操作
- 创建存储库的单独克隆,在其中执行过滤器存储库
- 在第二个克隆中,现在已清理(历史上不再有大文件),从您的第一个存储库导入您的工作
即对于第3点:
cd /path/to/second/clone
git --work-tree=/path/to/first/original/clone add .
git commit -m "Import work from first clone"
git push --force