编辑:如果您使用的是 GIT BASH,应该注意的一件事是 最好保持 AUTOCRLF 假
git config --global core.autocrlf false
====
============================================================我是 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.
您将尝试发送命令
git push -f origin master
我不确定你在这里到底在问什么。这些日志不是很有帮助。
但既然你问的是推...
通常,你从克隆存储库开始,或者运行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
Git for Windows: https://git-scm.com/download/win
参考手册: https://git-scm.com/doc
这是一个操作方法: https://githowto.com/
[更新]
这些日志更好。第 5 行告诉您需要做什么。git pull
一定有人在你之前推动了更改。因此,您需要将这些更改拉入存储库。修复任何冲突、提交和推送。
如果您阅读错误消息,它会显示:
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
注意第二行。
尝试执行git pull
,然后再次尝试git push
。它应该有效。
当我的用户第一次尝试推送到现有存储库时,我遇到了同样的错误。
我的问题是我的用户对存储库具有常规写入权限,但对分支没有。因此,如果这也是您第一次推送,请检查您的权限即可。
这通常发生在我将我的存储库推送到 GitHub 然后使用 GitHub 页面发布我的作品时,然后当我在本地机器中进行一些调整并尝试推送这些更改时,它被拒绝并显示错误消息,即远程存储库包含我的本地存储库中不存在的文件,所以我应该先尝试执行 git 拉取, 基本上是因为在发布到 GitHub 页面后,一些_config.yml
文件被添加到我们的存储库中,而我们的本地机器中不存在这些文件。
这可以使用git pull <remote fetch url>
首先解决,它将在本地机器上下载_config.yml
文件,然后我们可以使用 git push 命令进行推送。
我在这里回答这个问题,因为当我尝试搜索为什么我的 git push 命令不起作用时,这个问题是第一个谷歌搜索结果,尽管在这种情况下推送问题是由于不同的原因,但其他人可能会面临我的问题,所以我在这里添加了这个答案。