git - 从公共(public)存储库创建一个私有(private)分支,其中 base/trunk 是上游标签

标签 git github git-checkout git-tag

存储库设置

fork 私有(private)存储库

将公共(public)存储库克隆到私有(private)存储库

git clone --bare <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c3cdd0e4c3cdd0ccd1c68ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>:`upstream`/`upstream-repo`.git
cd `upstream-repo`.git
git push --mirror <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e0eef3c7e0eef3eff2e5a9e4e8ea" rel="noreferrer noopener nofollow">[email protected]</a>:`origin`/`origin-repo`.git

创建工作目录

git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="284f415c684f415c405d4a064b4745" rel="noreferrer noopener nofollow">[email protected]</a>:`origin`/`origin-repo`.git
git remote add upstream <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aec9c7daeec9c7dac6dbcc80cdc1c3" rel="noreferrer noopener nofollow">[email protected]</a>:`upstream`/`upstream-repo`
git fetch upstream

删除除主分支和旧分支之外的所有分支(为了清楚起见)

git push origin --delete `all branches excpt. master and legacy`

设置远程跟踪分支

git branch --set-upstream-to upstream/master master
git branch --set-upstream-to upstream/legacy legacy

让主干分支成为来自上游的标签

There is no such thing as a "remote Git tag"

来自:https://stackoverflow.com/a/35981459/8548024

因此该标签是本地标签,可以使用git fetch upper--tags进行更新

从本地标签创建原始主干(名为origin-repo)

git checkout tags/X.XX.XX -b `origin-repo`
git branch --set-upstream-to origin/`origin-repo` `origin-repo`
git push origin `origin-repo`
git pull

应用私有(private)差异

git checkout -b feat-diff
git apply feat-diff
git commit -m "applied feat-diff"
git push origin feat-diff

然后是 feat-diff 的 pull 请求(在 GitHub UI 中) 带有基础:origin-repo

我希望我的网络图看起来像这样:

master (upstream/master) ------------UM1--UM2--UM3--UM4--UM5------
                                       \
legacy (upstream/legacy)               UL1--UL2--UL3--UL4---------
                                              \
origin-repo (origin/origin-repo)              OR1--OR2-------OR3--
                                                     \      /
feat-diff (origin/feat-diff)                         FD1--FD2

相反,我得到了这张图。 (我的功能分支一直返回到我使用的标签)

The origin-repo looks like a feature branch and the feature branch looks like the origin

所以看起来我的主分支(origin-repo)是实际功能分支的一个功能分支,并且该功能分支一直回到标签。

为什么会这样?我该如何解决这个问题?

最佳答案

So it looks like my main branch (origin-repo) is a feature branch of the actual feature branch

给定一个提交结构,例如

  B <--(branch1)
 /
A
 \
  C <--(branch2)

A 与其中一个分支之间没有特殊关系。也许branch1 碰巧被称为master。也许branch2被称为feature。也许在创建 feature 之前 master 就存在于 A 中,但如果是这样,git 不会记住或关心它详细信息。

重点是,“功能分支”是一个描述性标签,对人们理解分支模型很有用。它不是 git 中的“物理真实”概念。两个分支都是分支,仅此而已。

and the feature branch goes all the way back to the tag.

分支根本不会“返回”。分支是指向提交的指针。您可能会认为该提交是“分支的尖端”或类似的东西,但实际上这就是分支的全部。历史上没有一条路径“也是分支的一部分”。历史记录中可以存在一条或多条可从分支到达的路径,但这些相同的路径也可以从另一分支到达,并且路径与任何一个分支之间不存在特殊关系超过另一个。

所以你真正想要的是你的可视化工具,试图迎合我们喜欢在分支上强加的抽象 - 例如提交路径和分支之间的关系- “猜错了”您希望看到哪个分支与历史中的哪条路径相关联。

我无法告诉你为什么它“猜错了”。我可以告诉你它必须猜测,因为你想看到的关系不是真实的。

关于git - 从公共(public)存储库创建一个私有(private)分支,其中 base/trunk 是上游标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49753358/

相关文章:

Git branch checkout 说虽然我的工作目录是干净的,但文件将被覆盖

git - 如何撤消 git rm

java - Heroku - git push/deployment 期间出错,此代码的相同版本已经构建

github - 将 Github 拉取请求转换为发布

git - 如何只获取特定分支的 Git 日志?

Git checkout 标签问题 - 标签未更改

git - 如何解决与 Github API merge 的冲突

git - 在使用 GIT 分支时何时不使用 "git rebase"?

javascript - 在 A 依赖于 B、B 依赖于 C 的情况下,并行处理 A、B 和 C 的完美工作流程是什么?

docker - github 工作流程 : "ECONNREFUSED 127.0.0.1:***" error when connecting to docker container