简体   繁体   English

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

[英]Why I always Got Error “Push to origin/master was rejected”?

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.

您将尝试发送命令

git push -f origin master

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 init and 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> ...

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"

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 Windows 版 Git: https : //git-scm.com/download/win
The reference manual: https://git-scm.com/doc参考手册: https : //git-scm.com/doc
Here's a how to: https://githowto.com/这是一个方法: https : //githowto.com/

[Update] [更新]
Those logs are better.那些日志更好。 Line 5 is telling you what you need to do.第 5 行告诉您需要做什么。 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.修复任何冲突,提交和推送。

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 push again.尝试执行git pull ,然后再次尝试git push It should work.它应该工作。

I had the same error when trying to push to an existing repository for a first time with my user.第一次尝试与我的用户推送到现有存储库时,我遇到了同样的错误。

My problem was my user had general WRITE permissions to repository but not to branches.我的问题是我的用户对存储库具有一般的 WRITE 权限,但对分支没有。 So if also it is your first time pushing, just check your permissions.因此,如果这也是您第一次推送,请检查您的权限。

This usually happens when I push my repository to GitHub and then use GitHub pages to publish my work, then later on when I make some tweaks in my local machine and try to push these changes it is rejected with the error message that the remote repo contains files that are not present in my local repo so I should try doing a git pull first, basically because after publishing to GitHub pages some _config.yml files are added to our repository which is not present in our local machine.这通常发生在我将我的存储库推送到 GitHub 然后使用 GitHub 页面发布我的工作时,然后当我在本地机器上进行一些调整并尝试推送这些更改时,它被拒绝并显示远程存储库包含的错误消息我的本地存储库中不存在的文件,所以我应该先尝试执行 git pull,主要是因为在发布到 GitHub 页面后,一些_config.yml文件被添加到我们的存储库中,而我们的本地机器中不存在这些文件。

This can be solved using a git pull <remote fetch url> first which will download the _config.yml file on our local machine and then we can push using the git push command.这可以通过首先使用git pull <remote fetch url>来解决,它会在我们的本地机器上下载_config.yml文件,然后我们可以使用 git push 命令进行推送。

I am answering this here since this question was the first google search result when I tried searching for why my git push command won't work, although the problem in push is due to a different reason in this case, others might face my issue so I added this answer here.我在这里回答这个问题,因为当我尝试搜索为什么我的 git push 命令不起作用时,这个问题是第一个谷歌搜索结果,尽管在这种情况下 push 中的问题是由于不同的原因,其他人可能会面临我的问题我在这里添加了这个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM