首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >git包:本地和远程回购之间的双向所有分支同步。

git包:本地和远程回购之间的双向所有分支同步。
EN

Stack Overflow用户
提问于 2016-06-29 11:16:28
回答 2查看 2.6K关注 0票数 4

机器A有互联网连接,而机器B没有。两者都有本地存储库,而机器A可以与Github交互。发展发生在这两台机器上。git-bundle被用来保持存储库的同步。

通常的同步流:

  1. 创建B中所有分支的一个包,并将其转移到A。
  2. 在A上克隆github存储库,将所有分支从包中拉到从github克隆的存储库中。将更新的存储库(所有分支)推送到github。
  3. 从github存储库创建所有分支的包。将包转移到B。将所有分支从包中拉到B上的存储库中。

有一种方法可以创建存储库的所有分支。但是,是否有一种方法可以同时将一个包的所有分支拉到本地存储库中呢?

在单分支存储库情况下,双向同步似乎是直接的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-29 12:14:43

由于捆绑与任何其他存储库一样-唯一的区别是一个包碰巧存储为一个文件-您可以使用git pull --all从包中获取所有分支并将它们合并到相应的跟踪分支中:

代码语言:javascript
复制
git pull --all /path/to/bundle

但是,请注意,--all选项仅适用于git fetch。这意味着只有当前的本地分支(即HEAD引用的分支)将被更新。如果您还想更新所有本地分支,您必须自己为它编写一个脚本,或者使用类似于盖特-的内容。

票数 1
EN

Stack Overflow用户

发布于 2020-07-10 12:08:18

向您的~/.gitconfig中添加以下pllbundle支git别名,然后运行git pullbundlebranches ../[filename].gitbundle

代码语言:javascript
复制
[alias]
  pullbundlebranches = "!f() { git pull --tags $1; git fetch $1; git bundle verify $1 | grep ' refs/heads/' | (while read line; do \
    commit=`echo $line | cut -d' ' -f1`; branch=`echo $line | sed 's_[^\\ ]*\\ refs/heads/__'`; \
    if git show-ref -q --heads $branch; then \
      old_commit=`git rev-parse $branch`; \
      if [ \"$old_commit\" = \"$commit\" ]; then \
        echo 'Skipping' $branch 'which is up-to-date at' $old_commit; \
      elif git merge-base --is-ancestor $branch $commit; then \
        current_branch=`git rev-parse --abbrev-ref HEAD`; \
        if [ \"$current_branch\" = \"$branch\" ]; then \
          git reset --hard $commit; \
        else \
          git branch -Dq $branch; git branch $branch $commit; \
        fi; \
        echo 'Updated' $branch 'from' $old_commit 'to' $commit; \
      elif git merge-base --is-ancestor $commit $branch; then \
        echo 'Skipping' $branch 'which is ahead of bundle version ('$commit')'; \
      else \
        echo 'Error:' $branch 'already exists and diverges from upstream found in bundle'; \
        echo 'You could switch to the bundle version as follows, but you might lose work.'; \
        echo 'git checkout -B' $branch $commit; \
      fi; \
    else \
      git branch $branch $commit; \
      echo 'Created' $branch 'pointing at' $commit; \
    fi; done); }; f"

它从包中获取,然后尝试更新/创建其中包含的每个分支。如果您自己的分支版本在前面或等于,则什么也不做。如果该分支与包中的版本不同,则会打印一个错误,说明如何切换到包版本,而不做任何操作。

运行的例子,然后强制一个分支到包中的版本,然后重新运行,这没有任何作用:

代码语言:javascript
复制
$ git pullbundlebranches ../../bundles/Jabberwocky_November_snapshot.gitbundle
From ../../bundles/Jabberwocky_November_snapshot.gitbundle
 * branch              HEAD       -> FETCH_HEAD
../../bundles/Jabberwocky_November_snapshot.gitbundle is okay
Error: develop already exists and diverges from upstream found in bundle
You could switch to the bundle version as follows, but you might lose work.
git checkout -B develop 6c5214a7bd9b10d5f9e49ab9eadaa1533867ebb7
Created feature/all_glory_to_him pointing at 645152be25e0e5d3eb80615c9173e88714b23ade
Created feature/praise_the_lord pointing at 6c5214a7bd9b10d5f9e49ab9eadaa1533867ebb7
Created feature/why_are_you_reading_the_branch_names pointing at a55f5f74d6b129d173770e91c5a0ffe8ff981e8e

$ git checkout -B develop 6c5214a7bd9b10d5f9e49ab9eadaa1533867ebb7
Reset branch 'develop'
Your branch is up to date with 'origin/develop'.

$ git pullbundlebranches ../../bundles/Jabberwocky_November_snapshot.gitbundle
From ../../bundles/Jabberwocky_November_snapshot.gitbundle
 * branch              HEAD       -> FETCH_HEAD
../../bundles/Jabberwocky_November_snapshot.gitbundle is okay
Skipping develop which is up-to-date at 6c5214a7bd9b10d5f9e49ab9eadaa1533867ebb7
Skipping feature/all_glory_to_him which is up-to-date at 645152be25e0e5d3eb80615c9173e88714b23ade
Skipping feature/praise_the_lord which is up-to-date at 6c5214a7bd9b10d5f9e49ab9eadaa1533867ebb7
Skipping feature/why_are_you_reading_the_branch_names which is up-to-date at a55f5f74d6b129d173770e91c5a0ffe8ff981e8e
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38098001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档