-2

I just modified 10 files in my project, and want to commit all these 10 files. What I did is:

git add -A

Then I found that this command add many untracked files, so I try to delete those untracked files from commit.

What I did (wrongly) is:

git rm -r --cached .

Then I found that I lost track of all files. Is there any command can recover my tracking file status?

wakeupbuddy
  • 971
  • 1
  • 8
  • 17
  • @PedroNascimento Different situation. My files are still in the disk. I am asking a command to recover the tracking status, not recover the files themself. – wakeupbuddy Mar 14 '15 at 05:56

1 Answers1

1

From what I did in a test git repository, git rm -r --cached . does not delete the files from the disk or reverts the changes to it but it unstages them.

Here is what I did

$git init
$touch test
$echo "Hello" > test
$git add .
$git commit -m "First commit"
$echo "Fellow" >> test
$git add .
$git rm -r --cached .
$cat test
hello
fellow

Therefore the only thing you'd have to do is add those files back.

I don't think there is any way to add the tracking back because you have removed the tracking. A soft reset to the current HEAD might be able to retrieve the tracking but I haven't tried this.

Prathik Rajendran M
  • 1,152
  • 8
  • 21
  • Yes. The files are still there in the disk. What i am asking is a command to recover the previous tracked file status, instead of manually adding them. – wakeupbuddy Mar 14 '15 at 05:51
  • Updated the answer with a possible solution. Take a backup before you try it. – Prathik Rajendran M Mar 14 '15 at 05:52
  • You want a `--mixed` style reset (`--mixed` is the default, so you can leave it out). That copies the given commit (default `HEAD`) into the index, which has the effect of undoing `git rm --cached`. Note that it also undoes `git add`s so you may want to choose particular paths to `git reset` instead. – torek Mar 14 '15 at 06:39