Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

git rm command unexpectedly staged the file instead of removing it

I removed test.txt file with this command:

git rm test.txt

then git status result was as:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Then I tried this command:

git reset head test.txt

to unstage changes and the result:

enter image description here

and finally I tried to remove the txt file with this command:

git rm test.txt

but the command unexpectedly **staged **the file instead of **removing **it:

enter image description here

Could you please explain misunderstanding with this command?

>Solution :

git rm test.txt not only records the test.txt deletion in the Git index, but also removes it from your working tree (local disk).

Unstaging the deletion still leaves the text.txt deleted on disk.
A new git rm simply re-stage the deletion.

If you had done a git rm --cached test.txt, then unstaging the deletion would have left a clean git status.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading