gpt4 book ai didi

Git:使用 git clean 排除一个文件

转载 作者:IT王子 更新时间:2023-10-29 00:57:27 24 4
gpt4 key购买 nike

我正在做一个大型 python 项目,如果 .pyc 和 *~ 文件我真的很烦。我想删除它们。我已经看到 git clean 的 -X 标志会删除未跟踪的文件。正如您想象的那样,我没有跟踪 .pyc*~ 文件。那会成功的。问题是我有一个 local_settings.py 文件,我想在 git clean 之后保留它。

所以,这就是我所拥有的。

.gitignore:

*.pyc
*~
local_settings.py

当我执行这个命令时:

git clean -X -n -e local_settings.py

我得到了这个结果列表:

Would remove local_settings.py
Would remove requirements.txt~
Would remove (other bunch of) ~ files
Would remove (other bunch of) pyc files

我不想删除 local_settings.py 文件。我已经尝试了很多方法来做到这一点,但我不知道如何完成它。

git clean -X -n -e local_settings.py
git clean -X -n -e "local_settings.py"
git clean -X -n --exclude=local_settings.py
git clean -X -n --exclude="local_settings.py"

似乎没有任何效果。

编辑:

为了后代,正确的做法是(感谢@Rifat):

git clean -x -n -e local_settings.py # Shows what would remove (-n flag)
git clean -x -f -e local_settings.py # Removes it (note the -f flag)

最佳答案

区别在于您使用的大写 X。使用小写的 x 而不是大写的。如:git clean -x

git clean -x -n -e local_settings.py # Shows what would remove (-n flag)
git clean -x -f -e local_settings.py # Removes it (note the -f flag)

来自 the git documentation :

   -x
Don't use the standard ignore rules read from .gitignore (per
directory) and $GIT_DIR/info/exclude, but do still use the ignore
rules given with -e options. This allows removing all untracked
files, including build products. This can be used (possibly in
conjunction with git reset) to create a pristine working directory
to test a clean build.

-X
Remove only files ignored by git. This may be useful to rebuild
everything from scratch, but keep manually created files.

关于Git:使用 git clean 排除一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11085795/

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