2016-09-06 109 views
0

我正在关注如何使用Git的教程。我可以将文件推送到新创建的GitHub仓库。但是我得到的错误:如何从GitHub中删除文件?

Updates were rejected because the remote contains work that you do not have locally. 

我猜这是因为GitHub库有一个readme.md文件在里面,由GitHub上提供的,而我的地方没有。所以我删除了该文件。但我仍然无法推动。我仍然收到同样的信息。

我猜这是因为我必须以某种方式'推动'在远程回购的变化(删除读我)?

有人会知道如何去做?

+0

不,您需要在推送前*拉*远程更改。试着用'git pull -r'在遥控器上添加你自己的提交。 – jonrsharpe

回答

1

So I deleted that file. However I still cannot push. I'm still getting the same message.

删除已创建一个新的提交,您没有本地。
问题不在于存在或不存在文件,而是在本地回购和远程回购之间存在不同的历史记录(提交集合)。

设置你的本地配置:

git config --global pull.rebase true 
git config --global rebase.autoStash true 

然后简单git pull

任何本地work in progress will be stashed,您自己的承诺重新启动,您的工作重新应用。然后,您可以查看,添加,提交和推送。

这样的组合(pull.rebase + rebase.autostash)可用,因为Git的2.6(9月2015):详见 “Can “git pull” automatically stash and pop pending changes?

0

使用git RM:

git rm file1.txt 
git commit -m "remove file1.txt" 

但是,如果你要删除的文件只从Git存储库中删除并且不从文件系统中删除它,使用:

git rm --cached file1.txt 

而且如果你把魔杖推到变长es to remote repo

git push origin branch_name