我刚接触git和github。
我想要在本地和远程将git的master
分支替换为我的另一个分支bridge
。问题是git无法解析bridge
分支的引用。这个问题是由于推送到github导致的。
git树是如何变成这样的:
- 通过Git GUI启动主分支。
- 继续使用,然后意识到它并不好用,并转换到Bash。
- 无法再将本地主分支推送到Github的master分支,因为本地主分支的末端比远程主分支的末端晚一个。
为解决这个问题,我创建了另一个名为bridge的分支。我不喜欢把bridge设置为默认值,因此我试图使用以下命令将其改回master:
git checkout better_branch git merge --strategy=ours master # 保存此分支的内容,但记录一个合并项 git checkout master git merge better_branch # 使主分支快进到合并点
在本地操作成功后,尝试推送时出现以下错误:
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 点击下面的链接可以看到我的git树截图(由于我需要更多的声誉才能发布一个有效的图片):http://i.imgur.com/FN9wHdi.jpg 如果我需要添加任何其他信息来改进问题,请告诉我。非常感谢您的时间,即使您只是阅读了我的问题!