Re: [PATCH] Use clean.requireforce to protect untracked files.
- From
Jiang Xin <worldhello.net@gmail.com>
- Date
- Jun 3, 2011, 16:20 UTC
- Message-ID
- <4DE909D5.9050805@gmail.com>
- In-Reply-To
- <7vipsnar23.fsf@alter.siamese.dyndns.org>
I do agree there are ignored-but-precious type of files exist in practice. Introducing such ignored-but-precious class through attributes or .gitignore is fine, and the definition of the class can broadcast to others through .gitattributes or .gitignore, it's cool. But it sounds a bit complicated.
This afternoon's hack on config variable "clean.requestForce" feets my needs, but it also has drawbacks:
1. Define a global "clean.requestForce" variable like this:
$ git config --global clean.requestForce LockIgnored
2. Then in one repository,
* You can : git clean -f
* But you cannot : git clean -f -x3. If want to override such global setting, simply
$ git config clean.requestForce true
The side-effect of this hack is that an unhacked git will complain:
fatal: bad config value for 'clean.requireforce' in .git/config
于 11-6-3 下午11:11, Junio C Hamano 写道:
Show 52 quoted lines
> Jiang Xin <worldhello.net@gmail.com> writes: > >> Untracked files may be significant for certain repositories, but if run the >> command "git clean -fdx" by accident, all untracked files will be lost. > > Don't add -x without thinking, then. It is the way to tell the command "I > want to remove all the untracked files and I REALLY MEAN IT". It is often > used to say "I do not trust Makefile and I want to remove what 'make > clean' would leave behind". > > A slightly related tangent is that we only have three classes of paths: > > - tracked ones > - untracked ones, where there are two subclasses > - unignored ones (e.g. new source file you haven't added) > - ignored ones (e.g. build artifacts like *.o files) > > and because of that, the general design is to consider "ignored" files > expendable during various operations. Sometimes people deliberately "ignore" > files that they consider not expendable, which is (by today's definition) > a wrong thing to do, but I think in the longer term we should add a way to > mark them as "ignored but precious". > > http://thread.gmane.org/gmane.comp.version-control.git/172818/focus=172846 > > Nobody has designed how this fourth class should behave (and how the > behaviour of the "ignored" should change, if any) yet, but a rough outline > would probably be: > > - precious files are the ones that are ignored (by today's definition, > i.e. .gitignore mechanism consideres they are ignored) but marked as > "precious" in some other way [*1*]. They will > > - not appear in "Untracked files:" section in "git status" output; > - not be added by "git add" without "-f", just like other ignored files; > - not be overwritten or removed to make room while switching branches; > - not be removed with "clean -f -x" [*2*]. > > - ignored files will stay to be "expendable". > > I suspect there may be some codepaths that incorrectly treat them as not > expendable, and protect their lossage. We would want to fix them after we > introduce the "precious" class. > > [Footnotes] > > *1* We could invent a way to sneak such entries in .gitignore, but I am > inclined to think it would be cleaner to define "precious" attribute and > let the attributes mechanism handle this. > > *2* This is just off the top of my head without thinking things > through. It might turn out that it makes more sense ot remove them.
-- 蒋鑫 北京群英汇信息技术有限公司 邮件: worldhello.net@gmail.com 网址: http://www.ossxp.com/ http://blog.ossxp.com/ 电话: 010-51262007, 13910430470 传真: 010-51262007