简体   繁体   English

恢复使用git rm --cached删除的文件

[英]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). 我试图忽略暂存区域(本地主机)对composer.pharcomposer.phar文件的更改。 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. .gitignore文件。 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? 我怎样才能回来或解决这个问题?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM