为什么空 Bitbucket 回购 "contain work" 而我 "do not have locally"?

Why does empty Bitbucket repo "contain work" that I "do not have locally"?

我的系统上有一个项目要存储在 Bitbucket 上。我在 Bitbucket 上创建了空项目(带有自述文件),然后在项目的根目录中执行了以下命令:

git init
git add --all
git commit -m "Initial commit"
git remote add origin <path-to-repo>
git push -u origin --all

我从 this link

得到了这些命令

它给了我 Updates were rejected because the remote contains work that you do not have locally 的错误。它建议做 git pull 但我担心如果我这样做会删除我在本地的工作。

我应该在这里做什么?

It gave me the error that Updates were rejected because the remote contains work that you do not have locally. It suggests doing git pull. What should I do here?

说到做到。 git pull

I'm worried that if I do that it will erase the work I have locally.

好吧,别担心了。这是git。一旦承诺,什么都不会丢失。

Why does empty Bitbucket repo “contain work” that I “do not have locally”?

好吧,你自己告诉我们答案:它不是空的! “有了自述文件,”你说。你有本地的自述文件吗?不,你不知道。因此,Bitbucket 存储库包含您在本地没有的工作。


EDIT 因此,您尝试遵循的说明存在的问题是,这些说明假设您的 Bitbucket 存储库是空的——而我们已经确定它不是。那么,在 git push -u 中,u 的要点是将您的 master 分支与 Bitbucket 的 master 分支相关联。您需要这样做才能推动或拉动,并且您可以在第一次推动时这样做。好的,但是 git push -u 仅在您 可以 推送时才有效。但是您不能 推送,因为您还没有提取自述文件。而且您无法提取自述文件,因为 git push -u 没有成功!第二十二条军规!!

解决方案是通过说(在 master 上)手动干预:

git branch -u origin/master

现在你已经建立了必要的协会,所以你可以git pullgit push简单明了就可以了。