2016-09-06 78 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