san*_*lto 34 git version-control git-clean
我正在开发一个大型python项目,如果.pyc和*〜文件,我真的很生病.我想删除它们.我已经看到-Xgit clean 的标志会删除未跟踪的文件.你可以想象,我不是跟踪.pyc也不是*~文件.那就是诀窍.问题是我有一个local_settings.py文件,我想在git clean之后保留.
所以,这就是我所拥有的.
的.gitignore:
*.pyc
*~
local_settings.py
Run Code Online (Sandbox Code Playgroud)
当我执行此命令时:
git clean -X -n -e local_settings.py
Run Code Online (Sandbox Code Playgroud)
我得到这个结果列表:
将删除local_settings.py
将删除requirements.txt~
将删除(其他一堆)〜文件
将删除(其他一堆)pyc文件
我不想删除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"
Run Code Online (Sandbox Code Playgroud)
似乎没有任何工作.
编辑:
对于后代,正确的方法是(谢谢@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)
Run Code Online (Sandbox Code Playgroud)
Rif*_*fat 27
请你试试小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)
Run Code Online (Sandbox Code Playgroud)
从git文档:
Run Code Online (Sandbox Code Playgroud)-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.
for*_*all 16
git clean -X -n --exclude="!local_settings.py"
Run Code Online (Sandbox Code Playgroud)
作品.当我用Google搜索并获得此页面时,我发现了这一点.
我将属于此类别的本地文件放在 .git/info/exclude 中(例如我的 IDE 项目文件)。你可以像这样进行清理:
git ls-files --others --exclude-from=.git/info/exclude -z | \
xargs -0 --no-run-if-empty rm --verbose
Run Code Online (Sandbox Code Playgroud)
在哪里:
您可以创建一个别名,例如:
git config --global alias.myclean '!git ls-files --others --exclude-from=.git/info/exclude -z | xargs -0 --no-run-if-empty rm --verbose --interactive'
Run Code Online (Sandbox Code Playgroud)
--interactive 意味着您必须执行 git myclean -f 来强制删除。
参考: http: //git-scm.com/docs/git-ls-files(加上默认.git/info/exclude的第一行)
| 归档时间: |
|
| 查看次数: |
16073 次 |
| 最近记录: |