Manolo
Manolo

Reputation: 26370

Recover files deleted with git rm --cached

I was trying to ignore the changes on composer.phar and composer.phar files from the staging area (local host). So I followed this post answer and did:

git rm --cached composer.lock 
git rm --cached composer.phar

and added:

/composer.lock 
/composer.phar

to .gitignore file. And all seemed to go as expected, as those files were still there, but they weren't followed.

But now, when I try to pull the changes from the server, these files are removed. I don't what to remove those files, just don't follow them. How could I come back or resolve this issue?

Upvotes: 3

Views: 5024

Answers (1)

Christoph
Christoph

Reputation: 28015

Well yes, you deleted the file from the index. You first need to get it back. You can either revert the commit which did that with

git revert sha_key_of_commit_that_deleted_it

or if you are ok about changing history you just reset your branch to the point before the change with

git reset sha_key_of_the_commit_where_sky_was_blue

Then, what you want to do is this to stop the file from receiving any further changes but keeping it the way it is:

git update-index --assume-unchanged /composer.lock

Upvotes: 3

Related Questions