git - git:从已推送到功能分支的远程删除不需要的文件
问题描述
我不小心将一个不需要的文件推送到了我的远程功能分支。
有这个documentation/~$screenshots.pptx
文件可能是我打开文档但没有关闭时自动生成的临时文件系统。
在我生成一个 PR 后,我发现这个文件也被推送了。
尝试使用 git rm documentation/~$screenshots.pptx
但收到此错误:
fatal: pathspec './documentation/~.pptx' did not match any files
由于我是我最后一次提交,所以我git reset --soft HEAD^
现在使用。
检查git status
:documentation/~$screenshots.pptx
列为new file: documentation/~$screenshots.pptx
.
试git rm documentation/~$screenshots.pptx
了还是fatal: pathspec './documentation/~.pptx' did not match any files
报错。
我怎样才能从我的 PR 中删除这个文件?
解决方案
如果文件被列为“新文件:”,这意味着它在索引中,可以提交。
在这种情况下,要使用的命令是:
git rm --cached 'documentation/~\$screenshots.pptx'
(尝试不同的语法,但重点仍然存在:您需要使用--cached
option)
然后提交并推送以更新您的 PR。
推荐阅读
- deployment - Azure 应用服务部署无法获取资源类型“Microsoft.Web/Sites”的资源 ID
- java - Eclipse jUnit 单元测试结果未显示
- julia - 非标准字符串文字如何避免标准字符串文字产生的语法错误?
- javascript - 为什么我的父组件中的状态落后了一步?
- r - R. 四舍五入到特定位数。不考虑小数点
- python - 如何在 CentOS8 上安装 Ansible
- unit-testing - 如何测试运行命令的 Go 函数?
- scala - 如何使用 sbt 或 Metals 从 vscode 开发和运行 spark scala
- django - 如何使用 Django 测试 Internet 连接?
- typescript - 具有匹配的通用回调的类型函数