git-svn - 当我的 master 已经是一个分支时,签出 svn 中已经存在的远程分支。解释一下这个.git/config

发布于 2024-10-17 14:47:14 字数 1727 浏览 4 评论 0原文

考虑到我加入的团队是如何使用 SVN 的,这是一个有点奇怪的问题。基本上,svn 存储库遵循标准布局,但主干确实在 1.5 年左右的时间里没有被触及,工作往往只发生在分支和分支的分支中。因此,我使用 git-svn 从代表下一个版本的活动分支的分支进行克隆,这也是 master 在我的本地 git 存储库中跟踪的内容。从现在开始,我们将 svn 中的这个分支称为“release”。使用 git-svn 来达到这个目的简直是太棒了。

现在,有人创建了一个“发布”的功能分支,我将其称为“功能”,我想将其下拉到我的本地分支,并提交给它。当然,我可以只将该分支克隆到本地另一个目录/git 存储库中,但我真正想做的是将“功能”镜像到本地 git 存储库中的本地分支中,以便在之间进行合并两者尽可能简单。我已经看到其他 stackoverflow.com 帖子展示了假设您使用 git svn init--stdlayout 的工作原理,但在我的例子中我没有这样做由于上述原因。

这是我的 .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://our.svn.server/svn/root/branches/release
    fetch = :refs/remotes/git-svn

我假设我的 [svn-remote] 部分中需要的是 branches = $something 但我不知道那是什么在这种情况下,$something 也不是 git checkout 的咒语和我对 .git/config 进行更改后需要的其他命令。

有什么建议吗?


编辑 - 以下工作:

所以我从头开始并执行以下克隆命令:

git svn clone https://my.svn.server/svn/root -T Branches/branch_I_want_as_master -b Branchs

经过大约 16 小时后,终于将所需的所有内容都拉下来了。结果 .git/config 看起来像这样:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://my.svn.server/svn/root
    fetch = branches/branch_I_want_as_master:refs/remotes/trunk
    branches = branches/*:refs/remotes/*

所以我知道这是有效的 - 我可以 git checkout -b name-of-a-branch name-of-a-branch 它给了我远程分支在我本地的 git 仓库中。以前的答案不是我需要的确切答案,但我已经投票了,因为它们很有帮助。

此时,我将接受仅解释其工作原理的答案,并且可能是一个有用的链接,该链接可以分解如何使用 .git/config 正确执行操作。

This is a bit of an oddball question given how the team I've joined is using SVN. Basically, the svn repository follows a standard layout, but trunk really hasn't been touched in 1.5 years or so and work tends to happen in branches and branches of branches only. As such, I've used git-svn to clone from the branch that represents the active branch for our next release and that is what master tracks in my local git repository. Let's call this branch in svn 'release' from here on out. Using git-svn for this purpose is just hunky dory.

Now, someone has created a feature branch off of 'release', that I'm going to call 'feature', that I'd like to pull down to a local branch of mine, and commit to as well. Sure, I can get away with just cloning that branch off into another directory/git repository locally, but what I'd really like to do is have 'feature' mirrored in a local branch within my local git repository as well to make merging between the two as straightfoward as possible. I've seen other stackoverflow.com posts show how this works assuming you've used git svn init with --stdlayout, but I didn't do that in my case for the reasons stated above.

Here is my .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://our.svn.server/svn/root/branches/release
    fetch = :refs/remotes/git-svn

I'm assuming what I need in my [svn-remote] section is a branches = $something but I don't know what that $something is in this case nor what incantation of git checkout and other commands I need after I make that change to .git/config.

Any suggestions?


Edit - The following works:

So I started from scratch and did the following clone command:

git svn clone https://my.svn.server/svn/root -T branches/branch_I_want_as_master -b branches

Which, after about 16 hours, finally pulled everything down that it needed to. The resultant .git/config looks like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://my.svn.server/svn/root
    fetch = branches/branch_I_want_as_master:refs/remotes/trunk
    branches = branches/*:refs/remotes/*

So I know this works - I can git checkout -b name-of-a-branch name-of-a-branch and it gives me the remote branch in my local git repo. The previous answers weren't the exact answers I needed, but I've upvoted since they were helpful.

At this point, I'll accept answer that just explains why this works and perhaps a useful link that breaks down how to do things properly with .git/config.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍暮颜 2024-10-24 14:47:14

您的存储库配置应如下所示:

[svn-remote "svn"]
url = https://our.svn.server/svn/root
fetch = branches/release:refs/remotes/git-svn
branches = branches/release/feature1:refs/remotes/branches/*
branches = branches/release/feature2:refs/remotes/branches/*

url 应指向存储库的根目录。 fetch 指向您的主干(实际上可以是任何分支),并且可以有任意数量的分支条目,指向您的功能 分支机构。

也许你应该从 scatch 构建你的 git 存储库,但这个配置是有效的。

You repository config should be looking like this:

[svn-remote "svn"]
url = https://our.svn.server/svn/root
fetch = branches/release:refs/remotes/git-svn
branches = branches/release/feature1:refs/remotes/branches/*
branches = branches/release/feature2:refs/remotes/branches/*

url should point at root of your repository. fetch points to your trunk (it could be any branch in fact), and there could be any number of branches entries, that points to your feature branches.

Maybe you should construct your git repository from scatch, but this config works.

花之痕靓丽 2024-10-24 14:47:14

您是否尝试过将 branches=.. 添加到 svn-remote 部分? (假设 url 直接指向您的 release 分支)。您将获得一个额外的 release 头来跟踪发布分支,但随后您也会跟踪所有其他分支,以便您可以检查它们。作为奖励,git svnbranch(可能)也可以用于创建新分支!

顺便说一句,您也可以只使用 --stdlayout 克隆您的 svn 存储库,然后将 master 设置为跟踪 release 而不是 trunk.这也不难做到。

Have you tried just adding branches=.. to your svn-remote section? (presuming url points directly at your release branch). You'll get an extra release head tracking the release branch, but then you'll get all the other branches tracked too so that you can check them out. As a bonus git svn branch will (probably) work for creating new branches too!

As a side note, you could have also just used --stdlayout to clone your svn repo, and then set master up to track release instead of trunk. That's not hard to do either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文