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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22007503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:45:44  来源:igfitidea点击:

Unable to resolve reference refs /refs/remotes/origin/branch while pushing after merging branches

gitgithubgit-bash

提问by Ishaan Taylor

New to git and github.

git 和 github 新手。

I want to replace the git masterbranch with my other branch bridgeboth locally and remotely. The problem is that git is unable to resolve the references for the bridgebranch. The problem arises from pushing to github.

我想在本地和远程master用我的另一个分支替换 git分支bridge。问题是 git 无法解析bridge分支的引用。问题来自于推送到 github。

How the git tree came to be this way:

git 树是如何变成这样的:

  1. Started master branch via the Git GUI.
  2. Continued and then realized it wasn't that great and transitioned to the Bash.
  3. Wasn't able to push to github anymore to master as the tip of the local master branch was one behind the tip of the remote counterpart.
  4. To circumvent, I created another branch called bridge. I didn't like that I had made bridge the default so I then tried to change it back to master using:

    git checkout better_branch
    git merge --strategy=ours master    # keep the content of this branch, but record a merge
    git checkout master
    git merge better_branch             # fast-forward master up to the merge
    
  5. It worked locally. However, when I tried to push I got the following:

    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 [email protected]: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 '[email protected]: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 [email protected]:NAMEtaylor/tabtrack.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]: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. I tried to git push -fbut:

    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 versions of Git)
    
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    Counting objects: 13, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (7/7), done.
    Writing objects: 100% (7/7), 898 bytes | 0 bytes/s, done.
    Total 7 (delta 5), reused 0 (delta 0)
    To [email protected]:NAMEtaylor/tabtrack.git
    
    • 1297c9f...bfa60d5 master -> master (forced update) error: unable to resolve reference refs/remotes/origin/bridge: No such file or d irectory error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master) $ git status On branch master nothing to commit, working directory clean
  7. Finally I tried to git push origin bridge --verboseas per advice on some stackoverflow questions:

    $ git push origin bridge --verbose
    Pushing to [email protected]:ishaantaylor/tabtrack.git
    Enter passphrase for key '/c/Users/Ishaan/.ssh/id_rsa':
    To [email protected]:ishaantaylor/tabtrack.git
     = [up to date]      bridge -> bridge
    updating local tracking ref 'refs/remotes/origin/bridge'
    error: unable to resolve reference refs/remotes/origin/bridge: No error
    error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    Everything up-to-date
    
  1. 通过 Git GUI 启动主分支。
  2. 继续然后意识到它不是那么好并过渡到 Bash。
  3. 无法再推送到 github 以掌握,因为本地 master 分支的尖端落后于远程对应分支的尖端。
  4. 为了规避,我创建了另一个名为bridge的分支。我不喜欢将桥设置为默认设置,因此我尝试使用以下方法将其改回主:

    git checkout better_branch
    git merge --strategy=ours master    # keep the content of this branch, but record a merge
    git checkout master
    git merge better_branch             # fast-forward master up to the merge
    
  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 [email protected]: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 '[email protected]: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 [email protected]:NAMEtaylor/tabtrack.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]: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 versions of Git)
    
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    Counting objects: 13, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (7/7), done.
    Writing objects: 100% (7/7), 898 bytes | 0 bytes/s, done.
    Total 7 (delta 5), reused 0 (delta 0)
    To [email protected]:NAMEtaylor/tabtrack.git
    
    • 1297c9f...bfa60d5 master -> master (forced update) error: unable to resolve reference refs/remotes/origin/bridge: No such file or d irectory error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master) $ git status On branch master nothing to commit, working directory clean
  7. 最后,我尝试git push origin bridge --verbose按照有关一些 stackoverflow 问题的建议:

    $ git push origin bridge --verbose
    Pushing to [email protected]:ishaantaylor/tabtrack.git
    Enter passphrase for key '/c/Users/Ishaan/.ssh/id_rsa':
    To [email protected]:ishaantaylor/tabtrack.git
     = [up to date]      bridge -> bridge
    updating local tracking ref 'refs/remotes/origin/bridge'
    error: unable to resolve reference refs/remotes/origin/bridge: No error
    error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    Everything up-to-date
    

A screenshot of my git tree is shown by clicking the link below (I need more rep to post a functioning pic): http://i.imgur.com/FN9wHdi.jpg

单击下面的链接可以显示我的 git 树的屏幕截图(我需要更多代表来发布功能正常的图片):http: //i.imgur.com/FN9wHdi.jpg

Please let me know if I need to add any other information in the question for it to become better. Thanks so much for your time, even if you just read my problem!

如果我需要在问题中添加任何其他信息以使其变得更好,请告诉我。非常感谢您的时间,即使您刚刚阅读了我的问题!

采纳答案by VonC

First, set the default push policy:

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

git config --global push.default simple

Then you can try and push your master branch

然后你可以尝试推送你的主分支

git push -u -f origin master

(you shouldn't need your bridge branch, since you merged master in it, and merge that branch back to master in point 4)

(你不应该需要你的桥分支,因为你在其中合并了 master,并在第 4 点将该分支合并回 master)