gpt4 book ai didi

Git 难题 : rm -r and . gitignore 不工作

转载 作者:太空狗 更新时间:2023-10-29 14:46:46 26 4
gpt4 key购买 nike

我刚刚将以下行添加到我的 .gitignore

*.pyc

1) 然后我运行命令

git rm -r --cached *.pyc

但它没有递归地工作,而是我得到了错误 fatal: pathspec 'RepoName.pyc' did not match any files

2) 更糟糕的是,当我下一次尝试

git add .

由于我的 .gitignore 而通常不会添加的所有文件都已准备提交。然后我删除了 *.pyc 行,但这种行为仍在继续。

有人知道这是怎么回事吗?

注意:

运行 git status 时,我没有将“通常被忽略”的文件视为未跟踪文件。

最佳答案

Shell 通配符不能递归使用。在执行 Got 之前,shell 在当前目录的上下文中展开它们。你需要类似的东西

 ls-files --other --ignored --exclude-standard -z | xargs -0 git rm --cached

选项说明:

  • ls-files --other --ignored --exclude-standard 显示应该忽略的文件。

  • -z 使用 NUL (\0) 分隔符输出,以避免文件名中出现空格问题。

  • xargs -0 为从 stdin 读取的每个以 NUL 分隔的记录运行下一个命令。

  • git rm --cached 仅从索引中删除,而不是从工作树中删除。

关于Git 难题 : rm -r and . gitignore 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22761811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com