Git 尝试推送时出现“先获取”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25862329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Giving "fetch first" error when trying to push
提问by FizzikalGrafiti
I am having my first introduction to git through a class I am taking. I have a number of files in a directory on my computer and am able to stage and commit them without a problem. However, when I try to push files to my github repository, I keep on getting this message:
我正在通过我正在上的课程第一次介绍 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.
Can anybody help me out with what this means and how to fix it? I've seen a few people with similar problems online, but I am BRAND NEW to git and not familiar enough with git's command line language yet. I'm a little hesitant to take certain suggestions, as I don't know whether it will solve the problem or make it worse.
任何人都可以帮助我了解这意味着什么以及如何解决它?我在网上看到过一些有类似问题的人,但我是 git 的新手,对 git 的命令行语言还不够熟悉。我有点犹豫是否接受某些建议,因为我不知道它是否会解决问题或使问题变得更糟。
Thanks!
谢谢!
回答by Tuncay G?ncüo?lu
Someone else (or you on some other machine) has pushed a changeset to the remote repository. You, on your local machine dont have those changes yet. So to solve the situation you first have to
其他人(或其他机器上的您)已将变更集推送到远程存储库。你,在你的本地机器上还没有这些变化。所以要解决这种情况,你首先必须
git pull
and then
进而
git push
However, you wont be able to git pull
while you have changes in your working tree, so before you pull/push, you first have to commit
or stash
your local changes. This, potentialy, might bring up a merge situation if remote changes overlap with your local ones.
但是,git pull
当您的工作树中有更改时,您将无法进行,因此在拉/推之前,您首先必须commit
或stash
您的本地更改。如果远程更改与本地更改重叠,这可能会导致合并情况。
回答by Purgoufr
I have been taken same error, then I solved this topic with used "--force" command. Briefly, write this command;
我遇到了同样的错误,然后我用“--force”命令解决了这个话题。简而言之,写下这个命令;
git push origin master --force
Attention: Probably, you tried to do push your codes over and over again before , that's why you took this error.My solution overwrite forcefully with your changeset. By this method your repository may cause mismatch other people's. But If you work alone (not like a group working), so you can use easily "--force" as I mentioned above.
注意:可能,您之前尝试过一遍又一遍地推送您的代码,这就是您犯此错误的原因。我的解决方案用您的变更集强行覆盖。通过这种方法,您的存储库可能会导致其他人的存储库不匹配。但是如果你单独工作(不像团队工作),那么你可以很容易地使用我上面提到的“--force”。
回答by Rubel Hossain
You can solve the problem by the command.
您可以通过命令解决问题。
git push origin master --force
回答by Emil Davtyan
It means that someone has pushed work to the remote repository, to merge it with your work you can run git pull --rebase
then push your combined work back to the remote repository.
这意味着有人已将工作推送到远程存储库,将其与您可以运行的工作合并,git pull --rebase
然后将合并后的工作推送回远程存储库。
回答by Kurian Benoy
git pullis a good option
git pull是一个不错的选择
But also: git push origin master --forcecommand will eventually help if the problem persists
而且: 如果问题仍然存在,git push origin master --force命令最终会有所帮助
回答by Loiane Cabral
I Haved this exactly same problem. I asked a friend for a help and he just copied the paste to the main repository and wrote the comand below: git remote show origin git add . git commit -m "including project2 in the main repository" git push -u origin master
我有这个完全相同的问题。我向一位朋友寻求帮助,他只是将粘贴复制到主存储库并在下面编写了命令: git remote show origin git add 。git commit -m “在主存储库中包含 project2” git push -u origin master
In the end I got two pastes in the main repository of two diferent projects.
最后我在两个不同项目的主存储库中得到了两个粘贴。
回答by Sh Huzaifa
@tunacy said it well.
@tunacy 说得很好。
someone has committed repository , so you just need to do
有人提交了存储库,所以你只需要做
git pull
and
和
git push
that's all you can also use
这就是你也可以使用的全部
git merge
for the merge
对于合并
回答by user10096908
! [rejected] master -> master (fetch first)'
Use:
$ git pull
then:
$ git push
Alternate solution:
$ git push --force origin master
but this will result in removal of files in your github repository so better prefer the first one it will pull the file first to your local repository and then you can push your work.
! [rejected] master -> master (fetch first)'
使用:
$ git pull
then:
$ git push
替代解决方案:
$ git push --force origin master
但这将导致删除 github 存储库中的文件,因此最好选择第一个,它将首先将文件拉到您的本地存储库,然后您可以推送您的工作。
回答by Bhavdeep Kaur
Follow the steps given below as I also had the same problem:
请按照下面给出的步骤操作,因为我也遇到了同样的问题:
$ git pull origin master --allow-unrelated-histories
(To see if local branch can be easily merged with remote one)
(看看本地分支是否可以轻松地与远程分支合并)
$ git push -u origin master
(Now push entire content of local git repository to your online repository)
(现在将本地 git 存储库的全部内容推送到您的在线存储库)
回答by Jayathma
I encountered this error when I opened terminal/GitBash in the wrong directory. Actually outside the repository folder. Check whether you are in correct location.
我在错误的目录中打开终端/GitBash 时遇到了这个错误。实际上在存储库文件夹之外。检查您是否在正确的位置。