git 和 github 的新手。
我想在本地和远程用我的另一个分支 bridge
替换 git master
分支。问题是 git 无法解析 bridge
分支的引用。问题出在push到github上。
git树是怎么变成这样的:
- 通过 Git GUI 启动主分支。
- 继续,然后意识到它不是那么好并过渡到 Bash。
- 无法再推送到 github 以掌握,因为本地 master 分支的尖端落后于远程分支的尖端。
为了规避,我创建了另一个名为 bridge 的分支。我不喜欢将 bridge 设置为默认设置,因此我尝试使用以下方法将其改回 master:
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
它在本地有效。但是,当我尝试推送时,我得到了以下信息:
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
我尝试了
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 git@github.com: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'.
最后,我根据一些 stackoverflow 问题的建议尝试
git push origin bridge --verbose
:$ git push origin bridge --verbose Pushing to git@github.com:ishaantaylor/tabtrack.git Enter passphrase for key '/c/Users/Ishaan/.ssh/id_rsa': To git@github.com: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
单击下面的链接可显示我的 git 树的屏幕截图(我需要更多代表才能发布正常运行的图片): http://i.imgur.com/FN9wHdi.jpg
如果我需要在问题中添加任何其他信息以使其变得更好,请告诉我。非常感谢您抽出宝贵时间,即使您刚刚阅读了我的问题!
最佳答案
首先,设置默认推送策略:
git config --global push.default simple
然后你可以尝试推送你的master分支
git push -u -f origin master
(你不应该需要你的 bridge 分支,因为你在其中 merge 了 master,并在第 4 点将该分支 merge 回 master)
关于git - merge 分支后推送时无法解析引用 refs/refs/remotes/origin/branch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22007503/