在合并分支后推送时无法解析引用 refs /refs/remotes/origin/branch。

6

我刚接触git和github。

我想要在本地和远程将git的master分支替换为我的另一个分支bridge。问题是git无法解析bridge分支的引用。这个问题是由于推送到github导致的。

git树是如何变成这样的:

  1. 通过Git GUI启动主分支。
  2. 继续使用,然后意识到它并不好用,并转换到Bash。
  3. 无法再将本地主分支推送到Github的master分支,因为本地主分支的末端比远程主分支的末端晚一个。
  4. 为解决这个问题,我创建了另一个名为bridge的分支。我不喜欢把bridge设置为默认值,因此我试图使用以下命令将其改回master:

    git checkout better_branch
    git merge --strategy=ours master    # 保存此分支的内容,但记录一个合并项
    git checkout master
    git merge better_branch             # 使主分支快进到合并点
    
  5. 在本地操作成功后,尝试推送时出现以下错误:

    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push
    warning: push.default is unset; its implicit value is changing in
    Git 2.0 from 'matching' to 'simple'. To squelch this message
    and maintain the current behavior after the default changes, use:
    git config --global push.default matching
    To squelch this message and adopt the new behavior now, use:
    git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa': To git@github.com:NAMEtaylor/tabtrack.git ! [rejected] master -> master (non-fast-forward) error: unable to resolve reference refs/remotes/origin/bridge: No error error: Cannot lock the ref 'refs/remotes/origin/bridge'. error: failed to push some refs to 'git@github.com:NAMEtaylor/tabtrack.git' hint: Updates were rejected because the tip of your current branch is behind 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.
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push origin master
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    To git@github.com:NAMEtaylor/tabtrack.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@github.com:NAMEtaylor/tabtrack.git'
    hint: Updates were rejected because the tip of your current branch is behind
    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.
    
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push origin bridge
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    error: unable to resolve reference refs/remotes/origin/bridge: No error
    error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    Everything up-to-date
    
  6. 我尝试使用git push -f,但是出现了以下错误:

    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (bridge)
    $ git checkout master
    Switched to branch 'master'
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master) $ git push -f warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use:
    git config --global push.default matching
    To squelch this message and adopt the new behavior now, use:
    git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older 点击下面的链接可以看到我的git树截图(由于我需要更多的声誉才能发布一个有效的图片):http://i.imgur.com/FN9wHdi.jpg 如果我需要添加任何其他信息来改进问题,请告诉我。非常感谢您的时间,即使您只是阅读了我的问题!
1个回答

2

首先,设置默认的推送策略:

git config --global push.default simple

然后您可以尝试推送您的主分支。
git push -u -f origin master

你不需要你的桥接分支,因为你在其中合并了主分支,并在第4步将该分支合并回主分支。


1
非常感谢您的回复!“分支主设置为跟踪来自原点的远程分支主。一切都是最新的。”这为什么是解决方案,它是如何解决问题的呢? - Ishaan Taylor
它允许您在本地分支和远程跟踪分支之间建立跟踪关系,这意味着 Git 知道何时以及在哪里推送。您可以在 https://dev59.com/X2Qn5IYBdhLWcg3wGT8X#17096880 上了解更多。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接