sarat sarat - 6 months ago 21
Git Question

How to unstage large number of files without deleting the content

I accidently added lot of temporary files using

git add -A

I manage to unstage the files using the following commands and managed to remove the dirty index.

git ls-files -z | xargs -0 rm -f
git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached

THe above commands are listed in the
git help rm
. But sadly, my files were also deleted on execution though I had given cache option. How clear the index without losing the content?

Also it would be helpful if someone can explain the way this pipe operation works.


Do NOT run "git reset --hard". It will not only unstage your added files, but will revert any changes you made in your working directory. If you created any new files in working directory, it'll not delete them though.

If all you want is to undo an overzealous "git add" run:

git reset

Your changes will be unstanged and ready for you to re-add as you please.