This adds a git-rm command which provides convenience similar to git-add, (and a bit more since it takes care of the rm as well). Like git-add, git-rm expands the given path names through git-ls-files. This means it only acts on files listed in the index. And it does act recursively on directories by default, (no -r needed as in the case of rm itself). When it recurses, it does not remove empty directories that are left behind. --- It wouldn't be too hard to make this act more like rm in requiring -r before recursing into directories. Let me know what people think about this. As before, if you'd prefer to fetch/pull this, you should be able to from: git://git.freedesktop.org/~cworth/git This time on the git-rm branch, (again merged into cworth for what that's worth). -Carl PS. I didn't change the Linus and Junio attribution since all of the code and documentation here is just minor changes from git-add. .gitignore | 1 + Documentation/git-rm.txt | 77 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 2 + git-rm.sh | 58 +++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletions(-) create mode 100644 Documentation/git-rm.txt create mode 100644 git-rm.sh cf3ff7a87defa6ced7e6a8b6d719a9f237a08314 diff --git a/.gitignore b/.gitignore index d7e8d2a..94f66d5 100644 --- a/.gitignore +++ b/.gitignore @@ -84,6 +84,7 @@ git-resolve git-rev-list git-rev-parse git-revert +git-rm git-send-email git-send-pack git-sh-setup diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt new file mode 100644 index 0000000..6095df8 --- /dev/null +++ b/Documentation/git-rm.txt @@ -0,0 +1,77 @@ +git-rm(1) +========= + +NAME +---- +git-rm - Remove files from the working tree and from the index. + +SYNOPSIS +-------- +'git-rm' [-n] [-v] <file>... + +DESCRIPTION +----------- +A convenience wrapper for rm and git-update-index --remove. For those +coming from cvs, git-rm provides an operation similar to "cvs rm -f". + + +OPTIONS +------- +<file>...:: + Files to remove from the working tree and the index. + +-n:: + Don't actually remove the file(s), just show if they exist in + the index. + +-v:: + Be verbose. + + +DISCUSSION +---------- + +The list of <file> given to the command is fed to `git-ls-files` +command to list files that are registered in the index and +are not ignored/excluded by `$GIT_DIR/info/exclude` file or +`.gitignore` file in each directory. This means two things: + +. You can put the name of a directory on the command line, and the + command will remove all files in it and its subdirectories (the + directories themselves are not removed); + +. Giving the name of a file that is not in the index does not + remove that file. + + +EXAMPLES +-------- +git-rm Documentation/\\*.txt:: + + Removes all `\*.txt` files that are in the index under + `Documentation` directory and its subdirectories. ++ +Note that the asterisk `\*` is quoted from the shell in this +example; this lets the command include the files from +subdirectories of `Documentation/` directory. + +git-rm git-*.sh:: + + Remove all git-*.sh scripts that are in the index. + Because this example lets the shell expand the asterisk + (i.e. you are listing the files explicitly), it does not + remove `subdir/git-foo.sh`. + + +Author +------ +Written by Linus Torvalds <torvalds@xxxxxxxx> + +Documentation +-------------- +Documentation by Junio C Hamano and the git-list <git@xxxxxxxxxxxxxxx>. + +GIT +--- +Part of the gitlink:git[7] suite + diff --git a/Makefile b/Makefile index 317be3c..e98b056 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ SCRIPT_SH = \ git-merge-one-file.sh git-parse-remote.sh \ git-prune.sh git-pull.sh git-push.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ - git-resolve.sh git-revert.sh git-sh-setup.sh \ + git-resolve.sh git-revert.sh git-rm.sh git-sh-setup.sh \ git-tag.sh git-verify-tag.sh git-whatchanged.sh \ git-applymbox.sh git-applypatch.sh git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ diff --git a/git-rm.sh b/git-rm.sh new file mode 100644 index 0000000..840c458 --- /dev/null +++ b/git-rm.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +USAGE='<file>...' +SUBDIRECTORY_OK='Yes' +. git-sh-setup + +show_only= +verbose= +while : ; do + case "$1" in + -n) + show_only=true + ;; + -v) + verbose=--verbose + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift +done + +# This is typo-proofing. If some paths match and some do not, we want +# to do nothing. +case "$#" in +0) ;; +*) + git-ls-files --error-unmatch -- "$@" >/dev/null || { + echo >&2 "Maybe you misspelled it?" + exit 1 + } + ;; +esac + +files=$( + if test -f "$GIT_DIR/info/exclude" ; then + git-ls-files \ + --exclude-from="$GIT_DIR/info/exclude" \ + --exclude-per-directory=.gitignore -- "$@" + else + git-ls-files \ + --exclude-per-directory=.gitignore -- "$@" + fi | sort | uniq +) + +case "$show_only" in +true) + echo $files + ;; +*) + rm $files + git-update-index --remove $verbose $files + ;; +esac -- 1.2.2.g73be-dirty
Attachment:
pgpJ3AhxsXVNO.pgp
Description: PGP signature