通过变基保持远程存储库同步

发布于 2024-08-02 19:30:36 字数 971 浏览 5 评论 0原文

我遇到一种情况,我必须将主题分支重新设置为主分支。没关系,这是正常的变基情况并且效果很好。

复杂的是当我试图让这个过程在裸露的远程存储库上同步时。

例如,

o--o--o origin/master
       \
        o--o origin/topic

o--o--o clone/master - tracking origin/master
       \
        o--o clone/topic - tracking origin/topic

现在我对克隆/主控进行了提交,并将其推送到原始/主控,到目前为止一切顺利。

o--o--o--n origin/master
       \
        o--o origin/topic

o--o--o--n clone/master - tracking origin/master
       \
        o--o clone/topic - tracking origin/topic

这就是我想要结束的地方:

o--o--o--n origin/master
          \
           o--o origin/topic

o--o--o--n clone/master - tracking origin/master
          \
           o--o clone/topic - tracking origin/topic

我似乎无法到达那里,请帮忙。

工作流程是:

  1. 克隆裸露的远程源
  2. 对克隆/主版本进行更改
  3. 将更改推送到 origin/master
  4. 将克隆/主题重新设置为原始或克隆主 - 似乎没有太大区别
  5. 现在我希望原点/主题能够反映变基,所以我想推送,但首先我必须拉动以使克隆/主题快进,然后我最终进行合并,其中包含来自克隆/主题的所有原始提交以及来自来源/主题位于顶部。

I have a situation where I will have to rebase a topic branch to a master. That's fine, it's the normal rebase case and works great.

The complication is when I'm trying to get this process to be in sync on a bare remote repository.

e.g.

o--o--o origin/master
       \
        o--o origin/topic

o--o--o clone/master - tracking origin/master
       \
        o--o clone/topic - tracking origin/topic

Now I make a commit to clone/master which I push to origin/master, so far so good.

o--o--o--n origin/master
       \
        o--o origin/topic

o--o--o--n clone/master - tracking origin/master
       \
        o--o clone/topic - tracking origin/topic

This is where I want to end up:

o--o--o--n origin/master
          \
           o--o origin/topic

o--o--o--n clone/master - tracking origin/master
          \
           o--o clone/topic - tracking origin/topic

I just can't seem to get there, please help.

The workflow is:

  1. Clone the bare remote origin
  2. Make changes to clone/master
  3. Push changes to origin/master
  4. Rebase clone/topic to either origin or clone master - doesn't seem to make too much difference
  5. Now I want the origin/topic to reflect the rebase so I want to push but first I have to pull to make clone/topic fast forward then I end up a merge which has all the original commits from clone/topic with all the commits from origin/topic on top.

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

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

发布评论

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

评论(2

梦明 2024-08-09 19:30:36

我会稍微修改您的工作流程,以避免推送 --mirror。

  1. git clone /path/to/origin # 克隆 master
  2. git checkout --track origin/topic
  3. git checkout master
  4. git add some_new_file; git commit -m“添加了一些新文件”
  5. git push origin/master
  6. git checkout topic #本地分支
  7. git rebase master
  8. git Push origin master #它将更新源上的 master
  9. git Push --force origin/topic :它将更新源上的主题

您需要 --force 因为 origin/topic 将更改祖先并且您已禁用快进检查。

I would modify slightly workflow that you have in order to avoid push --mirror.

  1. git clone /path/to/origin # clones the master
  2. git checkout --track origin/topic
  3. git checkout master
  4. git add some_new_file; git commit -m "added some new file"
  5. git push origin/master
  6. git checkout topic #Local branch
  7. git rebase master
  8. git push origin master #it will update master on origin
  9. git push --force origin/topic : it will update topic on origin

You need --force because origin/topic will change the ancestor and you have disable fast forward check.

带上头具痛哭 2024-08-09 19:30:36

显然,答案是使用 --mirror 标志进行推送。所以现在的工作流程是:

  1. git clone /path/to/origin # 克隆 master
  2. git checkout --track 来源/主题
  3. git 结账大师
  4. git 添加一些_新_文件; git commit -m“添加了一些新文件”
  5. git 推送原点/主站
  6. git checkout topic #本地分支
  7. git 变基大师
  8. git push --mirror origin #这是我错误的一步,仅仅常规推送是不够的

另请注意,除了我自己之外,我不会与任何人共享远程存储库,否则变基对其他开发人员来说是不公平的。

Apparently the answer is to push with the --mirror flag. So now the workflow is:

  1. git clone /path/to/origin # clones the master
  2. git checkout --track origin/topic
  3. git checkout master
  4. git add some_new_file; git commit -m "added some new file"
  5. git push origin/master
  6. git checkout topic #Local branch
  7. git rebase master
  8. git push --mirror origin #This is the step I had wrong, just a regular push is not good enough

Also note that I'm not sharing the remote repo with anyone but myself otherwise rebasing wouldn't be fair to the other developers.

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