从Git repo中删除文件
假设我在本地机器的repo上有以下文件:从Git repo中删除文件,git,github,Git,Github,假设我在本地机器的repo上有以下文件: index.php home.php text.php 我提交了所有更改,Github repo(origin)是我的本地机器的repo的精确副本 接下来,我将text.php重命名为unit\u test.php。是我干的。因此,现在我的Github repo有4个文件:index.php,home.phptest.php&unit\u test.php。鉴于,当前;y、 本地机器repo没有任何test.php文件。那么,如何从Github rep
index.php
home.php
text.php
我提交了所有更改,Github repo(origin
)是我的本地机器的repo的精确副本
接下来,我将
text.php
重命名为unit\u test.php
。是我干的。因此,现在我的Github repo有4个文件:index.php
,home.php
test.php
&unit\u test.php
。鉴于,当前;y、 本地机器repo没有任何test.php
文件。那么,如何从Github repo中删除此文件,因为这样做git rm test.php
不会给出这样的文件或目录
错误 假设您尚未在本地进行任何进一步的提交,我将备份并重试:
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
告诉git不要将某个文件从您的计算机推送到repo,因为您的计算机上已经没有该文件了,所以它会给您一个错误
您需要做的是首先拉取存储库,然后执行git rm test.php,然后提交和推送。我可以删除这个特定的本地分支,执行签出,然后执行git mv?我希望这能奏效?是的。我这样做了(删除了分支,然后再次从
源代码中签出该分支),它成功了。我会记得git mv的。谢谢,太好了。很乐意帮忙。根据我的经验,git
倾向于使用大多数普通bash文件系统命令的版本(ls、mv、rm…)