0 votes
1 view
in Devops and Agile by (28.1k points)

I accidentally added a lot of temporary files using git add -A

I managed 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, even though I had given the cache option. How can I clear the index without losing the content?

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

1 Answer

0 votes
by (48k points)

So, you have staged unwanted files and now you need to revert them without losing its content then you need to do:

git reset 

This command will revert your changes and unstage all the files, then those files will be ready to stage.

Thus, you can revert those unwanted files that are staged.

Note: 

Don’t use 

git reset --hard

Because this will revert the changes in the working directory, but in your scenario, it won’t delete the files but it makes changes to the working directory.

Refer: https://git-scm.com/docs/git-reset

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...