“获取-全部”在 git bare 存储库中,不会将本地分支同步到远程分支

发布于 2024-10-30 18:38:39 字数 642 浏览 0 评论 0原文

我正在尝试定期同步 git bare 存储库,我的本地分支是使用“--track”选项创建的。这是我的配置(没有不必要的东西):

[core]
        bare = true
[remote "origin"]
        url = [email protected]:Ummon/D-LAN.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "website"]
        remote = origin
        merge = refs/heads/website

我必须使用“cp”命令来更新本地分支:

 git fetch --all
 cp -r refs/remotes/origin/* refs/heads

是否有更优雅的解决方案?

I'm trying to synchronize periodically a git bare repository, my local branches are created using the "--track" option. here is my config (without unnecessary things):

[core]
        bare = true
[remote "origin"]
        url = [email protected]:Ummon/D-LAN.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "website"]
        remote = origin
        merge = refs/heads/website

I must use the 'cp' command to update the local branches:

 git fetch --all
 cp -r refs/remotes/origin/* refs/heads

Is there a more elegant solution?

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

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

发布评论

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

评论(1

千秋岁 2024-11-06 18:38:39

不要复制参考文件(糟糕!),而是使用 git update-ref

请注意,在推送而不是拉取时,您可以轻松地将所需内容保存到裸存储库中。

使用这个:

 git clone --mirror . /tmp/bareclone

创建您想要完全同步的裸存储库
现在,要将所有分支同步到裸克隆镜像,请使用

 git push /tmp/bareclone --mirror

注意,这还将删除不在源存储库中但(仍然)在裸克隆中的任何头。另请注意,您可以使用 send-pack 而不是在那里推送,因为这个接口相当低级,并且实际上是由 send-pack

HTH


实现的,正如评论者指出的那样,我稍微回避了这个主题,即似乎不可能立即执行相反的操作。然而,通过做一些稍微高级的事情,你可以离目标还有很长的路要走,比如:

1. 简单、安全并且相当平淡。

git fetch $url -- $(git ls-remote -h $url |
    while read sha ref; do echo "$ref:refs/remotes/fetched/${ref#refs/heads/}"; done)

设置“url=git://your.server/project.git”,例如

我确保引用是在一个相当安全的位置创建的。效果和doing非常相似。

git remote add fetched $url --fetch

所以没有什么太多,但是它向您展示了如何使用管道命令来实现它,所以我们现在可以根据我们的需求调整它们:

2.现在直接提取到本地分支(头)

如果您确定知道自己在做什么,您可以使用以下样式在本地复制分支:

git init --bare .
git fetch $url -- $(git ls-remote -h $url |
    while read sha ref; do echo "$ref:$ref"; done)

注意:如果您想强制更新(例如,由于上游变基、重置、过滤分支而没有快进拉动时,或修改的提交(一般来说 - 任何重写的历史记录)将 echo "$ref:$ref" 替换为 echo "+$ref:$ref"; (感谢Dov

3. 完整的 monty

这也可以组合起来,这样您也可以有一个远程定义。我建议这样做,因为这意味着本地分支实际上正在跟踪来自远程的分支,如果您不小心使用这些强大的获取命令破坏了这些分支上的一些本地提交,您将拥有更好的隔离/恢复选项< /em>

git init --bare .
git remote add fetched $url --fetch
git for-each-ref --format='%(refname:short)' -- 'refs/remotes/fetched/' |
    while read ref; do git branch -t "$(basename "$ref")" "$ref"; done

玩得开心,HTH

Instead of copying the ref files around (bad bad!) use git update-ref

Note that you can have what you wanted pretty easily to a bare repository when pushing instead of pulling.

Use this:

 git clone --mirror . /tmp/bareclone

to create the bare repository that you want to keep completely in synch
Now, to synch all the branches to the bareclone mirror, use

 git push /tmp/bareclone --mirror

NOTE that this will also remove any heads that aren't in the source repo but (still) are in the bareclone. Also note that you can use send-pack instead of push there because this interface is rather lowlevel and actually implemented by send-pack

HTH


As the commenter noted, I slighly avoided the subject that it doesn't seem possible at once to do the inverse. However, you can get a long ways towards the goal by doing something slightly advanced like:

1. Simple, safe and pretty unexciting.

git fetch $url -- $(git ls-remote -h $url |
    while read sha ref; do echo "$ref:refs/remotes/fetched/${ref#refs/heads/}"; done)

Set `url=git://your.server/project.git' e.g.

I made sure that the refs are created in a moderately safe location. The effect very similar to doing.

git remote add fetched $url --fetch

So there is nothing much, but it shows you how to use plumbing commands to achieve it, so we can now adapt them to our needs:

2. Fetch directly into local branches (heads)

Now if you are sure you know what you're doing you can use the following style to get the branches duplicated locally:

git init --bare .
git fetch $url -- $(git ls-remote -h $url |
    while read sha ref; do echo "$ref:$ref"; done)

Note: if you want to force update (e.g. when there is no fast-forward pull because of an upstream rebase, reset, filter-branch, or amended commit (in general -- any rewritten history) replace echo "$ref:$ref" by echo "+$ref:$ref"; (Thanks Dov)

3. The full monty

This could also be combined, so you can have a remote definition too. I'd recommend that because it will mean that the local branches are actually tracking the ones from the remotes, and you'll have better insulation/recovery options if you accidentally clobber some of the local commits on these branches with these powerful fetch commands

git init --bare .
git remote add fetched $url --fetch
git for-each-ref --format='%(refname:short)' -- 'refs/remotes/fetched/' |
    while read ref; do git branch -t "$(basename "$ref")" "$ref"; done

Have fun, HTH

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