[英]Deleting a file from Git repo
Lets say I had the following files on my local machine's repo: 可以说我在本地计算机的存储库中有以下文件:
index.php
home.php
text.php
I committed the all changes and the Github repo ( origin
) was an exact replica of my this local machine's repo. 我提交了所有更改,Github存储库( origin
)是我本机机器存储库的精确副本。
Next, I renamed text.php
to unit_test.php
. 接下来,我将text.php
重text.php
为unit_test.php
。 I committed it. 我承诺了 So, now my Github repo has 4 files: index.php
, home.php
test.php
& unit_test.php
. 所以,现在我的Github存储库有4个文件: index.php
, home.php
test.php
和unit_test.php
。 Whereas, current;y, the local machine repo doesn't have any test.php
file. 而当前; y,本地计算机存储库中没有任何test.php
文件。 So, how do I remove this file from Github repo as doing git rm test.php
gives No such file or directory
error. 因此,我如何从Github存储库中删除此文件,因为执行git rm test.php
No such file or directory
错误。
Assuming you haven't made any further commits locally yet, I would back up and try again: 假设您尚未在本地进行任何进一步的提交,我将备份并重试:
git reset --hard HEAD^ # revert index and tree one commit - to before the rename
git mv text.php unit_test.php # rename file in a manner git can track
git commit # The rename should staged automatically
git push
git rm
tells git to not push a certain file from your computer to the repo, which you don't have on your computer anymore, so it gives you an error. git rm
告诉git不要将计算机上的某个文件推送到存储库中,而您不再需要该文件,因此会出现错误。
What you need to do is pull the repository first then git rm test.php
and commit and push. 您需要做的是先拉存储库,然后git rm test.php
并提交并推送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.