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

Kir*_*ans 5 git github git-bash git-shell

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

git config --global core.autocrlf false
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

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

推送时的错误

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.
Run Code Online (Sandbox Code Playgroud)

daz*_*311 8

您将尝试发送命令

git push -f origin master
Run Code Online (Sandbox Code Playgroud)


Jer*_*naw 3

我不确定你在这里到底想问什么。而且这些日志并没有多大帮助。

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

一般来说,您首先会克隆一个存储库,或者运行git init并创建一个存储库。

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

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

git add <file1> <file2> ...

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

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

git commit -m "My commit message"

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

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

您可以使用以下命令查看您的遥控器 git remote -v

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

然后推到它 git push upstream master

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

[更新]
这些日志更好。第 5 行告诉您需要做什么。 git pull
一定有人在你之前推动了改变。因此,您需要将这些更改放入您的存储库中。修复任何冲突、提交并推送。