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

2 views
Skip to first unread message

Rob Townley

unread,
Oct 16, 2017, 12:29:08 AM10/16/17
to Omaha Linux User Group, omaha-ma...@googlegroups.com
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 <notifi...@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 <pro...@noreply.github.com>
Cc: Robert Townley <rob.t...@gmail.com>, Manual <man...@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 'TRANSLATION_NOTES.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:

EXAMPLES
       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, or mute the thread.


Reply all
Reply to author
Forward
0 new messages