Git:用git clean排除一个文件 [英] Git: Exclude a file with git clean

查看:668
本文介绍了Git:用git clean排除一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个大型的python项目,如果.pyc和*〜文件真的很糟。我想删除它们。我已经看到git clean的 -X 标志会删除未跟踪的文件。你可以想象,我没有跟踪 .pyc *〜文件。这将成为诀窍。问题是我有一个 local_settings.py 文件,我想在git clean之后保留它。



<所以,这就是我所得到的。



.gitignore:

  *。pyc 
*〜
local_settings.py

当我执行这个命令:

  git clean -X -n -e local_settings.py 



我得到以下结果清单:


local_settings.py

将删除requirements.txt〜

将删除(其他一堆)〜文件

将删除(其他一堆)pyc文件
p>

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

  git clean  - X -n -e local_settings.py 
git clean -X -n -elocal_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#显示将删除的内容(-n标志)
git clean -x -f -e local_settings.py#删除它(注意-f标志)


解决方案

你可以用小的 x 来代替大写的。像 - git clean -x

  git clean -x -n  - e local_settings.py#显示将删除的内容(-n标志)
git clean -x -f -e local_settings.py#删除它(注意-f标志)

git文档
$ b


  -x 
不要使用标准忽略规则读取从.gitignore(每
目录)和$ GIT_DIR / info / exclude,但仍使用-e选项提供的忽略
规则。这允许删除所有未跟踪的
文件,包括构建产品。这可以使用(可能在
与git reset结合)创建一个原始工作目录
来测试一个干净的版本。

-X
只删除git忽略的文件。这可能对从头开始重新生成
的所有东西很有用,但保留手动创建的文件。



i'm working on a big python project, and i'm really sick if .pyc and *~ files. I'd like to remove them. I've seen that the -X flag of git clean would remove untracked files. As you can imagine, i'm not tracking .pyc nor *~ files. And that would make the trick. The problem is that i've a local_settings.py file that I'd like to keep after the git clean.

So, this is what I've got.

.gitignore:

*.pyc
*~
local_settings.py

When I execute this command:

git clean -X -n -e local_settings.py

I get this list of results:

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

I don't want to remove the local_settings.py file. I've tryed lots of ways to do it, but i can't figure out how to acomplish it.

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"

And nothing seems to work.

EDIT:

For posterity, the right way to do it is (Thanks @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)

解决方案

Will you please try that with small x instead of the capital one. Like - 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)

From 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排除一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆