git - 如何从 git 的所有分支中删除名为 .css 的文件
问题描述
我正在使用一个 git 存储库,该存储库中以某种方式命名.css
了一个文件。这在 Windows 中签出时会导致错误(但在 Linux 中可以正常工作)。
如何从git的所有分支中删除此文件,而不会意外从所有分支中删除所有 css 文件?
解决方案
这是您如何为单个分支执行此操作的方法,因为“所有分支”相当模糊,我将自动化/迭代部分留在所有分支上,让您按照自己的喜好进行操作(如果您没有的话,我建议您手动进行许多分支都有这个有问题的文件)
# First checkout the branch - WARNING - Note I use
# --force here to make sure `git status` is clean.
# I'm relying on it later when doing `git add -A`.
# The --force flag will delete any uncommited local changes,
# so make sure you don't have any of those before running
# the following command
git checkout --force my_branch
# Now delete the `*.css` file. Note the single quotes, they
# are crucial to prevent the shell from doing expansion on the asterisk:
rm -- '*.css'
# Add "all" the changes (The deletion of the file should be the only change):
git add -A
# Now commit
git commit -m 'Removed evil *.css file'
# And push
git push origin my_branch
我没有故意使用git rm
(它结合了删除和git add
一个命令),因为我无法让它忽略*
作为一个字符,它试图变得聪明并删除.css
项目中的所有文件。编辑:有关在 git 命令中指定文字星号的方法,请参阅torek 的答案
推荐阅读
- ios - 在本机反应中使动画连续
- android - Android Studio ClipArt 不显示任何图标
- compiler-construction - 如何使用 APEX 编译器将 Ada 代码从 Sun Solaris 10 迁移到 11
- c# - 将 ForEach 表转换为 Datatable Jquery 表的简单方法?
- c# - mvc视图层中div中的条件
- azure - Azure 应用程序网关和 Key Vault - GW 看不到续订的 SSL 证书
- hy - HyLang:如何在 hy 中最简单的 for 循环?
- r - R:按时间段聚合时间序列列表
- c# - 将旧版 Entity Framework 4.0 升级到 5.0
- gdb - gdb 可以打印扩展的预处理器/宏结果吗?