[olug] Fwd: [progit/progit2] Why does "git rm" remove recursively even without "-r" option? (#847)

Rob Townley rob.townley at gmail.com
Sun Oct 15 23:29:06 CDT 2017

Heads Up.  As you know, *rm* is for remove or delete files using bash.  *`git
rm`* is much more recursively aggressive than super careful *`rm`, *
The* recursive-by-default `git rm` behavior *may not be so bad since the
deleted files should be in the previous commit, but you may not notice for
a while.
*`git rm`* should not delete files that have not been added yet.

The following is from https://github.com/progit/progit2

---------- Forwarded message ----------
From: Robert P. J. Day <notifications at github.com>
Date: Sun, Oct 15, 2017 at 2:36 AM
Subject: Re: [progit/progit2] Why does "git rm" remove recursively even
without "-r" option? (#847)
To: progit/progit2 <progit2 at noreply.github.com>
Cc: Robert Townley <rob.townley at gmail.com>, Manual <
manual at noreply.github.com>

Followup ... there have been some *very* interesting and enlightening
explanations about how "git rm" globbing works, and it's not intuitive. The
major observation is that simple globbing with "git rm" happily crosses
directory boundaries, so the command:

$ git rm log/\*.log

will remove all .log files under log/ *recursively*. Simple test to prove
this using the Pro Git repo itself, with a dry run (as above):

$ git rm -n '*.asc'
rm 'LICENSE.asc'
rm 'README.asc'
rm 'book/01-introduction/1-introduction.asc'
rm 'book/01-introduction/sections/about-version-control.asc'
rm 'book/01-introduction/sections/basics.asc'
rm 'book/01-introduction/sections/command-line.asc'
rm 'book/01-introduction/sections/first-time-setup.asc'
rm 'book/01-introduction/sections/help.asc'
rm 'book/01-introduction/sections/history.asc'
rm 'book/01-introduction/sections/installing.asc'
rm 'book/02-git-basics/1-git-basics.asc'

and so on, and so on. The man page for "git rm" does in fact make this
clear, the book should probably note this as well:

       git rm Documentation/\*.txt
           Removes all *.txt files from the index that are under the
Documentation directory and
           any of its subdirectories.

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/progit/progit2/issues/847#issuecomment-336692513>, or mute
the thread

More information about the OLUG mailing list