gpt4 book ai didi

即使在 'non-fast-forward updates' 之后,Git 也会给出 'git pull' 错误

转载 作者:太空狗 更新时间:2023-10-29 14:01:04 25 4
gpt4 key购买 nike

Github 是我项目的默认存储库(只是“origin”重命名为“github”)。发生了一些事情,以至于“git push”导致“非快进更新”错误,即使“git push github master”有效。 “git pull”和“git pull github master”都表示最新状态。我如何 (a) 确保 Github 上没有未 merge 的更改,以及 (b) 更正非快进错误?

$ git status
# On branch master
nothing to commit (working directory clean)
$ git pull
Already up-to-date.
$ git pull github master
From github.com:MikeBlyth/mission_net
* branch master -> FETCH_HEAD
Already up-to-date.
$ git push github master
Everything up-to-date
$ git push
To git@github.com:MikeBlyth/mission_net.git
! [rejected] add_command -> add_command (non-fast-forward)
error: failed to push some refs to 'git@github.com:MikeBlyth/mission_net.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.

我的git配置文件是

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "github"]
url = git@github.com:MikeBlyth/mission_net.git
fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
remote = github
merge = refs/heads/master
[remote "heroku"]
url = git@heroku.com:joslink.git
fetch = +refs/heads/*:refs/remotes/heroku/*
merge = refs/heads/master
[remote "heroku"]
url = git@heroku.com:joslink.git
fetch = +refs/heads/*:refs/remotes/heroku/*

最佳答案

'git push' 的语法支持显式和速记版本。显式版本 git push github master 适合你。简写版本 git push 没有。

如果你使用速记版本,你不会告诉 git 使用哪个远程分支以及应该将哪个本地分支推送到哪个远程分支。因此 git 必须猜测你的意思。

您可以使用 Remote 的设置和 push.default 配置来配置它:

   push.default
Defines the action git push should take if no refspec is given on
the command line, no refspec is configured in the remote, and no
refspec is implied by any of the options given on the command line.
Possible values are:

· nothing - do not push anything.

· matching - push all matching branches. All branches having the
same name in both ends are considered to be matching. This is
the default.

· upstream - push the current branch to its upstream branch.

· tracking - deprecated synonym for upstream.

· current - push the current branch to a branch of the same
name.

查看 git branch -vv 以检查当前分支跟踪的分支。然后检查 git config --get push.default 以验证它是否按照您的预期进行。

关于即使在 'non-fast-forward updates' 之后,Git 也会给出 'git pull' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com