gpt4 book ai didi

git - 使用新的 .gitignore 文件重新同步 git repo

转载 作者:IT王子 更新时间:2023-10-29 01:16:43 26 4
gpt4 key购买 nike

是否可以在更新 gitignore 文件后“刷新”git 存储库?

我刚刚向我的 gitignore 添加了更多的忽略(?),并想删除与新文件匹配的存储库中已有的东西。

最佳答案

.gitignore file not ignoring”中提到的解决方案有点极端,但应该可行:

# rm all files
git rm -r --cached .
# add all files as per new .gitignore
git add .
# now, commit for new .gitignore to apply
git commit -m ".gitignore is now working"

(确保首先提交您想要保留的更改,以避免发生任何 jball037 comments below 的事件。
--cached 选项将使您的文件在磁盘上保持不变。)

您在博文“Making Git ignore already-tracked files”中还有其他更细粒度的解决方案:

git rm --cached `git ls-files -i --exclude-standard`

Bassim建议 in his edit :

路径中有空格的文件

In case you get an error message like fatal: path spec '...' did not match any files, there might be files with spaces in their path.

You can remove all other files with option --ignore-unmatch:

git rm --cached --ignore-unmatch `git ls-files -i --exclude-standard`

but unmatched files will remain in your repository and will have to be removed explicitly by enclosing their path with double quotes:

git rm --cached "<path.to.remaining.file>"

关于git - 使用新的 .gitignore 文件重新同步 git repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7075923/

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