Git:在裸仓库中更改Active Branch的正确方法? [英] Git: Correct way to change Active Branch in a bare repository?
问题描述
我有一个裸仓库,用作我项目的中央商店。所有开发人员都可以使用 问题是,如何正确更改 Active Branch ?我可以简单地直接对 我在repo 我试过 我尝试过 我正在使用git版本 我猜测没有办法通过 如果您有权访问远程裸回购,文章建议: git clone< repo>
来与之共享。当他们完成克隆时,他们会得到master分支的结账(除非他们执行 git clone -n
),因为 repo.git / HEAD > code>包含
ref:refs / heads / master
,这是活动分支。
repo.git / HEAD
文件进行破解,但这看起来令人讨厌,而且很好,哈。
.git
目录中尝试了 git checkout< otherbranch>
,但是失败了,因为我没有' t
git update-ref HEAD refs / heads / otherbranch
但刚刚更新refs / heads / master与refs / heads / otherbranch相同(好的,我在一个虚拟库中做了一个,不是我的产品!)
git update-ref --no-deref HEAD refs / heads / otherbranch
并且几乎可以工作。它更新了 HEAD
文件,但是它将它设置为由 refs / heads / otherbranch
指向的提交的SHA1。 。
1.7.0.2.msysgit.0
。
git push
来做到这一点,因为允许所有和各种改变你的默认分支似乎有点不安全(!),但是当然在repo .git
目录中有一个更好的方法,比直接破解 HEAD
file。
git symbolic-ref HEAD refs / heads / mybranch
这将更新仓库中的HEAD文件,使其包含:
ref:refs / heads / mybranch
记录在 git-symbolic-ref
如果您无法访问远程回购,请参阅我以前的回答。
请记住,像 不更改远程存储库的默认分支。 不会变更 git remote set-head
:
它只会将本地存储库中存储的远程跟踪分支更改为 refs / remotes /< name> / HEAD
HEAD
本身(同样,只有 refs / remotes /< name> / HEAD
),因此需要
git symbolic-ref
。
所以 git remote set-head
不是答案在这里。如果你有直接的访问远程仓库,
git symbolic-ref HEAD
就是。
I have a bare repository that's used as the central store for my project. All the developers do git clone <repo>
to share with it. When they do the clone, they get a checkout of the master branch (unless they do git clone -n
) because repo.git/HEAD
contains ref: refs/heads/master
, making this the Active Branch.
The question is, how do I change the Active Branch properly? I could simply hack the repo.git/HEAD
file directly, but that seems nasty and, well, hacky.
I tried doing git checkout <otherbranch>
in the repo .git
directory, but that failed because I wasn't in a work tree.
I tried git update-ref HEAD refs/heads/otherbranch
but that just updated refs/heads/master to be the same as refs/heads/otherbranch (okay, I did that one in a dummy repository, not my production one!)
I tried git update-ref --no-deref HEAD refs/heads/otherbranch
and that almost worked. It updated the HEAD
file, but it set it to the SHA1 of the commit pointed to by refs/heads/otherbranch
.
I'm testing with git version 1.7.0.2.msysgit.0
.
I'm guessing there's no way to do this through git push
, as allowing all and sundry to change your default branch seems a bit unsafe (!), but surely there's a better way to do it in the repo .git
directory than directly hacking the HEAD
file.
If you have access to the remote bare repo, this article suggests:
git symbolic-ref HEAD refs/heads/mybranch
Which will update the HEAD file in your repository so that it contains:
ref: refs/heads/mybranch
as documented in the git-symbolic-ref
If you don't have access to the remote repo, see my previous answer.
Remember that a command like git remote set-head
:
doesn't change the default branch of the remote repo.
It only changes a remote tracking branch stored in your local repo asrefs/remotes/<name>/HEAD
doesn't change
HEAD
itself (again, onlyrefs/remotes/<name>/HEAD
), hence the need forgit symbolic-ref
.
So git remote set-head
is not the answer here.
git symbolic-ref HEAD
is, if you have direct access to the remote repo.
这篇关于Git:在裸仓库中更改Active Branch的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!