实习生已经从我们的master
分支创建了一个分支,并将其命名为Master
!
现在,当我想将我的代码合并到真实的master
并执行git pull
时,我会收到如下错误:
error: Ref refs/remotes/origin/master is at bce957a261a1ef76eaec043243c5d036f8d5483e but expected afba8312e4c8bba8d3e6ba440463381dfe819461
From http://github.company.com/InternID/her_prototype
! afba831..db56ee6 master -> origin/master (unable to update local ref)
我们使用的是OSX,它对文件名不区分大小写,因此master
和Master
看起来相同。
如何将实习生创建的Master
分支重命名为其他分支?
答案 0 :(得分:3)
我没有快速的测试方法,但有点像:
git checkout master
git branch -m temp
git checkout --track origin/Master
git push origin HEAD:renamed
git push origin :Master
git checkout temp
git branch -D Master
git branch -m master
应该这样做。
在mac上制作区分大小写的磁盘映像,克隆到它并在那里进行修复可能会更容易。
编辑:我做了一个快速测试,它的工作原理如上所述。可能有一些捷径;我会把它留给评论者退出。这是一个成绩单(#
内联评论):
$ git remote update # update repository
Fetching origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From /Volumes/Disk Image/remote
* [new branch] Master -> origin/Master
$ git branch -a # note bad name 'Master'
* master
remotes/origin/HEAD -> origin/master
remotes/origin/Master
remotes/origin/master
$ git checkout master
Already on 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
$ git branch -m temp # rename 'master' for a moment
$ git checkout --track origin/Master # checkout the bad branch
Branch Master set up to track remote branch Master from origin.
Switched to a new branch 'Master'
$ git push origin HEAD:renamed # push it with a different name
Total 0 (delta 0), reused 0 (delta 0)
To /Volumes/Disk Image/remote
* [new branch] HEAD -> renamed
$ git push origin :Master # delete bad branch on remote
To /Volumes/Disk Image/remote
- [deleted] Master
$ git checkout temp # checkout renamed 'master'
Switched to branch 'temp'
$ git branch -D Master # delete bad local branch
Deleted branch Master (was 5343242).
$ git branch -m master # change 'master' name back
$ git branch -a # presto!
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/renamed
答案 1 :(得分:1)
我的解决方案类似于@ Carl's,但更简单
以下步骤将重命名 Master
分支到new_branch_name
分支(确保您在区分大小写的系统中执行此操作)< / p>
git checkout -t origin/Master
git checkout -b new_branch_name
git push origin new_branch_name:new_branch_name
git push origin :Master