尝试推送时 Git 给出 "fetch first"错误

标签 git push fetch

我正在上一门课,这是我第一次接触 git。我的计算机上的目录中有许多文件,并且能够毫无问题地暂存和提交它们。但是,当我尝试将文件推送到我的 github 存储库时,我不断收到此消息:

Pushing to https://github.com/BigMeanCat/CMDA
To https://github.com/BigMeanCat/CMDA
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/BigMeanCat/CMDA'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

任何人都可以帮助我了解这意味着什么以及如何解决它吗?我在网上看到一些人有类似的问题,但我是 git 的新手,对 git 的命令行语言还不够熟悉。我有点犹豫是否接受某些建议,因为我不知道它是否会解决问题或使问题变得更糟。

谢谢!

最佳答案

其他人(或您在其他机器上)已将变更集推送到远程存储库。你,在你的本地机器上还没有这些变化。所以要解决你首先要解决的问题

git pull

然后

git push

但是,当您的工作树中有更改时,您将无法 git pull,因此在 pull/推之前,您首先必须 commitstash 您的本地更改。如果远程更改与本地更改重叠,这可能会引发 merge 情况。

关于尝试推送时 Git 给出 "fetch first"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25862329/

相关文章:

windows - gitstats在windows中使用gitstats报错的解决方法

git - 我如何正确地强制 Git 推送?

javascript - 有没有办法将变量从 client.js 文件发送到您的 node.js 文件?

javascript - 请求从 fetch api 发布的数据

git - 在推送之前我如何知道提交/更改列表

git - 你能从 git 提交中挑选一个或多个大块头吗?

assembly - 错误的整数入栈

推送后github无法访问文件夹

ios - 如何实现 iOS 后台获取?

eclipse - 如何使用 Egit 查看特定标签?