git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Removing files

From
EWEric Wong <normalperson@yhbt.net>
Date
Jan 11, 2007, 23:19 UTC
Message-ID
<20070111231955.GB13564@localdomain>
In-Reply-To
<7vejq12nlu.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
Show 34 quoted lines
> David Kågedal <davidk@lysator.liu.se> writes:
> 
> > I'm wondering what the best way to commit the removal of a file is.
> 
>  $ rm -f foo
>  $ git-commit -a
> 
> > git status shows:
> >
> >   $ git status
> >   # On branch refs/heads/messages
> >   # Changed but not added:
> >   #   (use "git add <file>..." to incrementally add content to commit)
> >   #
> >   #       deleted:    foo
> 
> Suggesting "git add" to record the deletion feels insane.  Is
> this what we still do?  I think there have been much work 
> in this area recently so the wordings might have already fixed.
> 
> > Ok, so that didn't work.  Let's try rm instead:
> >
> >   $ git rm foo
> >   fatal: pathspec 'foo' did not match any files
> >
> 
> The above message is from an older version of git-rm, but the
> one that will be in v1.5.0 is not any better.  It errs out with
> "No such file or directory".  A workaround using today's tool is
> to do "git rm --cached fo"
> 
> I think the right fix is to suggest "git add/rm" in status
> output and make "git rm" not barf if the user has already
> removed the file from the working tree.

Would having a command like 'hg addremove' make things easier? I've been using the below script since my early days of using git, but I don't think I've ever published it. If you want I can create a patch against git.git

----------------------------------------------------------------------- #!/bin/sh # like the addremove command in mercurial

if test "x$1" = "x-h"
then
	echo "Usage: git-addrm [<path>]"
	exit 0
fi
SUBDIRECTORY_OK=1
. git-sh-setup || die "Not a git archive"
EXCLUDE_ARGS=--exclude-per-directory=.gitignore
if test -f "$GIT_DIR/info/exclude"
then
	EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude-from=$GIT_DIR/info/exclude"
fi
set -e
git-ls-files -z --deleted $EXCLUDE_ARGS "$@"| \
	git-update-index --remove -z --stdin
git-ls-files -z --others $EXCLUDE_ARGS "$@" | \
	git-update-index --add -z --stdin
-----------------------------------------------------------------------
-- 
Eric Wong
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 15 in “Removing files”
  1. David KågedalJan 11, 2007
  2. Alex RiesenJan 11, 2007
  3. Seth FalconJan 11, 2007
  4. Junio C HamanoJan 11, 2007
  5. Eric WongJan 11, 2007
  6. Junio C HamanoJan 11, 2007
  7. git-status: wording update to deal with deleted files.Junio C Hamano, Jan 11, 2007
  8. Carl WorthJan 11, 2007
  9. Junio C HamanoJan 12, 2007
  10. Carl WorthJan 12, 2007
  11. Jakub NarebskiJan 12, 2007
  12. Jeff KingJan 12, 2007
  13. Juergen RuehleJan 12, 2007
  14. Carl WorthJan 11, 2007
  15. Jeff KingJan 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.