6

实习生从我们的分支创建了一个分支master并命名了它Master!现在,当我想将我的代码合并到真实代码中master并执行 agit 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 上,它对文件名不区分大小写,所以看起来和它一样masterMaster

我的问题

如何Master将实习生创建的这个分支重命名为其他名称?

4

2 回答 2

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
于 2013-08-21T00:03:03.870 回答
1

我的解决方案类似于@Carl,但更简单

以下步骤将分支重命名为分支(确保在区分大小写的系统中执行此操作)Masternew_branch_name

git checkout -t origin/Master
git checkout -b new_branch_name
git push origin new_branch_name:new_branch_name
git push origin :Master
于 2013-08-21T01:01:52.260 回答