* Removing a newly added file @ 2007-03-26 14:59 Santi Béjar 2007-03-26 18:55 ` [PATCH] git-rm: don't remove newly added file without -f Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Santi Béjar @ 2007-03-26 14:59 UTC (permalink / raw) To: Git Mailing List Hi *, when you try removing a newly added file it success and removes the file from the working directory. So if you do: $ echo "newly added file" > new $ git add new $ git rm new the file "new" is lost, it is not in the index, neither in HEAD. At this moment the only way to recover the file new is searching for unreachable objects. (Am I missing something?) I think that the "git rm new" should remove "new" from the index or should fail, maybe with: $ git rm new error: 'new' is not in HEAD (hint: try --cached) Santi ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] git-rm: don't remove newly added file without -f 2007-03-26 14:59 Removing a newly added file Santi Béjar @ 2007-03-26 18:55 ` Jeff King 2007-03-26 21:11 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Jeff King @ 2007-03-26 18:55 UTC (permalink / raw) To: Santi Béjar; +Cc: git, Junio C Hamano, Johannes Schindelin Given this set of commands: $ echo "newly added file" >new $ git add new $ git rm new the file "new" was previously removed from the working directory and the index. Because it was not in HEAD, it is available only by searching for unreachable objects. Instead, we now err on the safe side and refuse to remove a file which is not referenced by HEAD. Signed-off-by: Jeff King <peff@peff.net> --- > I think that the "git rm new" should remove "new" from the index or > should fail, maybe with: Something like this? I think there are still some issues with the safety valve, though; this triggers on 'git rm --cached new' which should be a perfectly safe operation. However, that is not new to this change; we already erroneously trigger the valve on a --cached removal of a file with matching index and working directory, but mismatch with HEAD. Example: git-add foo git-commit -m 'added foo' echo changes >>foo git-add foo git-rm --cached foo ;# should be OK because we have working copy I think the logic for "safe to remove" and "safe to remove --cached" needs to be separate. I will take a look. Also, this just implements "error, try -f" when it would be safe to drop back to --cached for that file. Is there any interest in trying to make git-rm more clever in this way, or is simple and predictable preferred? builtin-rm.c | 18 ++++-------------- 1 files changed, 4 insertions(+), 14 deletions(-) diff --git a/builtin-rm.c b/builtin-rm.c index 00dbe39..bf42003 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -89,20 +89,10 @@ static int check_local_mod(unsigned char *head) if (ce_match_stat(ce, &st, 0)) errs = error("'%s' has local modifications " "(hint: try -f)", ce->name); - if (no_head) - continue; - /* - * It is Ok to remove a newly added path, as long as - * it is cache-clean. - */ - if (get_tree_entry(head, name, sha1, &mode)) - continue; - /* - * Otherwise make sure the version from the HEAD - * matches the index. - */ - if (ce->ce_mode != create_ce_mode(mode) || - hashcmp(ce->sha1, sha1)) + if (no_head + || get_tree_entry(head, name, sha1, &mode) + || ce->ce_mode != create_ce_mode(mode) + || hashcmp(ce->sha1, sha1)) errs = error("'%s' has changes staged in the index " "(hint: try -f)", name); } -- 1.5.1.rc2.615.g992d-dirty ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] git-rm: don't remove newly added file without -f 2007-03-26 18:55 ` [PATCH] git-rm: don't remove newly added file without -f Jeff King @ 2007-03-26 21:11 ` Junio C Hamano 2007-03-26 21:17 ` Johannes Schindelin 0 siblings, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2007-03-26 21:11 UTC (permalink / raw) To: Jeff King; +Cc: Santi Béjar, git, Johannes Schindelin Jeff King <peff@peff.net> writes: > Given this set of commands: > > $ echo "newly added file" >new > $ git add new > $ git rm new > > the file "new" was previously removed from the working > directory and the index. Because it was not in HEAD, it is > available only by searching for unreachable objects. I am not sure if this is a problem, as the user asked it to be removed. It somehow feels to me that the change (I am not convinced your patch should be called a "fix" rather than a "behaviour change") would cause more confusion. Unstaging request would have looked like "git reset HEAD new", wouldn't it? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] git-rm: don't remove newly added file without -f 2007-03-26 21:11 ` Junio C Hamano @ 2007-03-26 21:17 ` Johannes Schindelin 2007-03-26 21:33 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Johannes Schindelin @ 2007-03-26 21:17 UTC (permalink / raw) To: Junio C Hamano; +Cc: Jeff King, Santi Béjar, git Hi, On Mon, 26 Mar 2007, Junio C Hamano wrote: > Jeff King <peff@peff.net> writes: > > > Given this set of commands: > > > > $ echo "newly added file" >new > > $ git add new > > $ git rm new > > > > the file "new" was previously removed from the working > > directory and the index. Because it was not in HEAD, it is > > available only by searching for unreachable objects. > > I am not sure if this is a problem, as the user asked it to be > removed. It somehow feels to me that the change (I am not > convinced your patch should be called a "fix" rather than a > "behaviour change") would cause more confusion. I agree it would add to confusion. It is well established that "git rm" also removes the file _in the working directory_. If you don't want the file to be deleted, but only the corresponding entry _in the index_, use "git rm --cached". Ciao, Dscho ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] git-rm: don't remove newly added file without -f 2007-03-26 21:17 ` Johannes Schindelin @ 2007-03-26 21:33 ` Junio C Hamano 2007-03-26 22:22 ` Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2007-03-26 21:33 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Jeff King, Santi Béjar, git Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: > On Mon, 26 Mar 2007, Junio C Hamano wrote: > >> Jeff King <peff@peff.net> writes: >> >> > Given this set of commands: >> > >> > $ echo "newly added file" >new >> > $ git add new >> > $ git rm new >> > >> > the file "new" was previously removed from the working >> > directory and the index. Because it was not in HEAD, it is >> > available only by searching for unreachable objects. >> >> I am not sure if this is a problem, as the user asked it to be >> removed. It somehow feels to me that the change (I am not >> convinced your patch should be called a "fix" rather than a >> "behaviour change") would cause more confusion. > > I agree it would add to confusion. > > It is well established that "git rm" also removes the file _in the working > directory_. > > If you don't want the file to be deleted, but only the corresponding > entry _in the index_, use "git rm --cached". Actually, thinking about it a bit more, I think Jeff's patch is in line with the current behaviour. Looking at the cases where we prevent 'git rm' without '-f' succeeding currently, the motivation is to save the user from mistakenly saying "remove" when the user earlier said "this change matters in the next commit" to us. For example, with "edit existing-file; git add existing-file", the user said the new state of the file matters in the next commit. And we refuse to remove, saying "foo has changes staged". By saying "edit new-file; git add new-file", the user expressed the intent to add that content to the upcoming commit. Saying "git rm" later is reverting that intent. Jeff's patch does exactly the same thing for new files what we already do for existing ones --- we ask for a confirmation when "git rm" is given for existing files that has staged changes, saying "you earlier said you want changes to this file in the next commit. are you sure you have changed your mind?" Having said that, we do _not_ ask for confirmation when you do "git add existing-file" after doing "edit ; git add", which is theoretically inconsistent, but rm is special so that is probably Ok. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] git-rm: don't remove newly added file without -f 2007-03-26 21:33 ` Junio C Hamano @ 2007-03-26 22:22 ` Jeff King 2007-03-26 22:36 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Jeff King @ 2007-03-26 22:22 UTC (permalink / raw) To: Junio C Hamano; +Cc: Santi Béjar, git, Johannes Schindelin On Mon, Mar 26, 2007 at 02:11:42PM -0700, Junio C Hamano wrote: > Unstaging request would have looked like "git reset HEAD new", > wouldn't it? Yes, I think I am still in the habit of using "git rm" from its old usage. I unstage so rarely that I don't think my fingers have adjusted. > "git rm" later is reverting that intent. Jeff's patch does > exactly the same thing for new files what we already do for > existing ones --- we ask for a confirmation when "git rm" is Yes, regardless of how git-rm is "supposed" to be used, I think this patch is worth it for two reasons: 1. consistency; we should treat newly added files just like existing files (after all, content is content, right?) 2. safety; I work under the assumption that I can do whatever I want with git-rm, and it will _never_ lose my data unless I use -f. Granted, without this patch my data would still be available somewhere in the object database, but it is hard to find and susceptible to pruning. > Having said that, we do _not_ ask for confirmation when you do > "git add existing-file" after doing "edit ; git add", which is > theoretically inconsistent, but rm is special so that is > probably Ok. Hmm, yes, I agree that is inconsistent. However, it's such a common workflow that forcing a '-f' would become meaningless. And you _can_ rescue the blob from the object database in a pinch, though finding it can be tedious. -Peff ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] git-rm: don't remove newly added file without -f 2007-03-26 22:22 ` Jeff King @ 2007-03-26 22:36 ` Junio C Hamano 0 siblings, 0 replies; 7+ messages in thread From: Junio C Hamano @ 2007-03-26 22:36 UTC (permalink / raw) To: Jeff King; +Cc: Santi Béjar, git, Johannes Schindelin Jeff King <peff@peff.net> writes: > Hmm, yes, I agree that is inconsistent. However, it's such a common > workflow that forcing a '-f' would become meaningless. And you _can_ > rescue the blob from the object database in a pinch, though finding it > can be tedious. That's exactly the reason why I mentioned this inconsistency between add vs rm "tongue-in-cheek". We really do not want to require -f for common situations so much that it ends up training people's fingers to type -f without thinking, which would render the safety option meaningless. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-03-26 22:36 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-03-26 14:59 Removing a newly added file Santi Béjar 2007-03-26 18:55 ` [PATCH] git-rm: don't remove newly added file without -f Jeff King 2007-03-26 21:11 ` Junio C Hamano 2007-03-26 21:17 ` Johannes Schindelin 2007-03-26 21:33 ` Junio C Hamano 2007-03-26 22:22 ` Jeff King 2007-03-26 22:36 ` Junio C Hamano
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).