git 为什么我总是收到错误“推送到原点/主站被拒绝”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50538508/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:08:02  来源:igfitidea点击:

Why I always Got Error "Push to origin/master was rejected"?

gitgithubgit-bashgit-shell

提问by Kira Nofans

EDIT: one of the things should be aware of if you are using git bash is that BETTER TO KEEP AUTOCRLF FALSE

编辑:如果您使用 git bash,应该注意的一件事是最好保持 AUTOCRLF FALSE

git config --global core.autocrlf false

========================================================

================================================== ======

I'm new to git and I got problems deploying files...

我是 git 的新手,但在部署文件时遇到了问题...

I just pulled files successfully (?) using commands, and now I'm trying to push...

我刚刚使用命令成功拉取了文件(?),现在我正在尝试推送...

Commit Logs below: (I have several reverts because I have failed to commit several times due to LF, CRLF, or untracked Files errors)

提交日志如下:(我有几次还原,因为由于 LF、CRLF 或未跟踪的文件错误,我多次提交失败)

And in AS I got "Push to origin/master was rejected"

在 AS 我得到“推送到原点/主站被拒绝”

The Error when pushing

推送时的错误

hint: Updates were rejected because the tip of your current branch is behind
!   refs/heads/master:refs/heads/master [rejected] (non-fast-forward)
Done
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
18:53:20.176: [Lab1_movie] git -c core.quotepath=false -c 
log.showSignature=false pull --progress --no-stat -v --progress origin 
master
From https://github.com/kiranofans/Lab1_MovieApp
 * branch            master     -> FETCH_HEAD
 = [up to date]      master     -> origin/master
fatal: refusing to merge unrelated histories
18:57:26.215: [Lab1_movie] git -c core.quotepath=false -c 
log.showSignature=false push --progress --porcelain origin 
refs/heads/master:master
github --credentials get: github: command not found
github --credentials store: github: command not found
error: failed to push some refs to 
'https://github.com/kiranofans/Lab1_MovieApp.git'
To https://github.com/kiranofans/Lab1_MovieApp.git
!   refs/heads/master:refs/heads/master [rejected] (non-fast-forward)
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
Done
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

采纳答案by Jerinaw

I'm not sure what exactly you're asking here. And those logs are not very helpful.

我不确定你在这里问的到底是什么。而这些日志并不是很有帮助。

But since you're asking about pushing...

但是既然你问的是推...

Generally you've started out by cloning a repo or you've run git initand created one.

通常,您是通过克隆一个 repo 开始的,或者您已经运行git init并创建了一个。

You then edit or create files in that repo.

然后在该存储库中编辑或创建文件。

You then need to stage those file to be committed.

然后,您需要暂存这些要提交的文件。

git add <file1> <file2> ...

git add <file1> <file2> ...

You can see what's been staged with git status

你可以看到上演的内容 git status

If everything looks good you can commit those changes

如果一切看起来不错,您可以提交这些更改

git commit -m "My commit message"

git commit -m "My commit message"

If you've cloned a remote repository, and you have permissions to push to it

如果您已经克隆了一个远程存储库,并且您有权推送到它

git push <remote> <branch>so something like git push origin master

git push <remote> <branch>所以像 git push origin master

You can view your remotes with git remote -v

你可以查看你的遥控器 git remote -v

You can add a remote if you don't see the remote you need in the list git remote add <give it a name> <the URL to the repo>so something like git remote add upstream https://github.com/me/myrepo.git

如果在列表中没有看到所需的遥控器,则可以添加遥控器, git remote add <give it a name> <the URL to the repo>例如 git remote add upstream https://github.com/me/myrepo.git

And then push to it git push upstream master

然后推到它 git push upstream master

Git for Windows: https://git-scm.com/download/win
The reference manual: https://git-scm.com/doc
Here's a how to: https://githowto.com/

Windows 版 Git:https: //git-scm.com/download/win
参考手册:https: //git-scm.com/doc
以下是操作方法:https: //githowto.com/

[Update]
Those logs are better. Line 5 is telling you what you need to do. git pull
Some one must have pushed changes before you did. So you need to pull those changes into your repo. fix any conflicts, commit, and push.

[更新]
那些日志更好。第 5 行告诉您需要做什么。 git pull
一定有人在你之前推动了变化。所以你需要将这些更改拉到你的仓库中。修复任何冲突、提交和推送。

回答by ResetACK

If you read the error message, it says:

如果您阅读错误消息,它会说:

hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

Pay attention to that second line.

注意第二行。

Try to do a git pull, and then try and git pushagain. It should work.

尝试做一个git pull,然后再试git push一次。它应该工作。