我正在上一门课,这是我第一次接触 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/推之前,您首先必须 commit
或 stash
您的本地更改。如果远程更改与本地更改重叠,这可能会引发 merge 情况。
关于尝试推送时 Git 给出 "fetch first"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25862329/