5

I was trying to make my .gitingore work (Link to the question :) ).

I have just done

git rm . -r --cached 

and now I have a whole list of deleted files when I enter:

git status -s 

Is this normal? Can i safetly commit all my changes?

Or maybe there is a way to undo this command?

PS: I was trying to understand what this command do but i've only found this: http://brianloomis.wordpress.com/2009/08/10/git-rm-r-cached/ And it's not so clear to me.

PS 2: OK :) To save my skin I've made a reset:

git reset HEAD *

The DELETED files went bye bye :) There are no longer visible in git status -s . But still is it safe to do the command:

git rm . -r --cached and then add and commit it? 
Community
  • 1
  • 1
Mr.TK
  • 1,743
  • 2
  • 17
  • 22

1 Answers1

5

"safe"? What it does is empty the index and commit the deletion of those files, without removing them from the working tree (your disk)

That means all those files become un-tracked (private).

Usually, you don't commit after such a command. You reset (as you did).
That can force content drivers (like a smudge script) or other .gitattributes directives to be applied again on all files.

You can see that command used in the GitHub help page "Dealing with line endings".

git rm --cached -r .
# Remove everything from the index.

git reset --hard
# Write both the index and working directory from git's database.

Again, in this case: no commit, only a reset.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Would it be correct to change "commit the deletion" to "stage the deletion"? – unutbu Apr 08 '14 at 14:01
  • @unutbu "stage" means recording in the index (stage). That is what git rm --cached does already. If you commit after that, you create a new commit which records the deletion of those files in the git repo. – VonC Apr 08 '14 at 14:24
  • So if i would do add and commit after rm --cached command i would simply remove all files from repository?? :O (Not sure if i got this right) :) – Mr.TK Apr 09 '14 at 05:39
  • @Mr.TK no: if you would commit *directly after* the git rm --cached, you would record the deletion, meaning anyone else cloning the latest commit wouldn't see those file. Since you did a `git rm --cached -r`, those files are still on your disk (working tree), but untrack. If you did a `git add` right after the `git rm`... that wouldn't do much, but restore the index you just emptied. – VonC Apr 09 '14 at 05:42
  • Oh... so that was a safe thing to do. :) I wanted to clear indexes on those files. Also I still wanted them in repo. – Mr.TK Apr 09 '14 at 05:48
  • 1
    @Mr.TK Yes. I prefer a `git reset` (with or without the `--hard`) to restore in the index. `git add` can add "too much". – VonC Apr 09 '14 at 05:50
  • Thank You for your help. Have a wonderful night/day - what ever you having now (i assume beer is an option too ) ;) – Mr.TK Apr 09 '14 at 05:51
  • @Mr.TK you are welcome. Almost 8AM here. The day is just starting. – VonC Apr 09 '14 at 05:52
  • So... We are in the same timezone. :) 11:20 AM :) – Mr.TK Apr 09 '14 at 09:20