从Git repo中删除文件

时间:2013-06-07 08:07:24

标签: git github

假设我的本地计算机上有以下文件:

index.php
home.php
text.php

我提交了所有更改,Github repo(origin)完全复制了我本地机器的回购。

接下来,我将text.php重命名为unit_test.php。我承诺了。所以,现在我的Github仓库有4个文件:index.phphome.php test.php& unit_test.php。然而,当前; y,本地机器仓库没有任何test.php文件。那么,如何从Github repo中删除此文件,因为git rm test.php会导致No such file or directory错误。

2 个答案:

答案 0 :(得分:0)

假设您尚未在本地进行任何进一步的提交,我会备份并再试一次:

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

答案 1 :(得分:0)

git rm告诉git不要将某个文件从您的计算机推送到您的计算机上没有的repo,因此它会给您一个错误。

您需要做的是首先拉出存储库然后git rm test.php并提交并推送。