如何确定特定分支的源分支?

编程入门 行业动态 更新时间:2024-10-25 05:15:05
本文介绍了如何确定特定分支的源分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在git中有一个分支,想弄清楚它最初是从哪个分支分支出来的,在什么时候提交.

I have a branch in git and want to figure out from what branch it originally was branched and at what commit.

Github似乎知道,因为当您执行一次拉取请求时,它通常会自动设置它应该进入的分支,但是我无法从命令行中手动确定如何做到这一点.

Github seems to know, since when you do a pull request it usually automatically sets up what branch it should go into, but I can't figure out how to do this manually from the command line.

让我添加一个具体示例:

Let me add a concrete example:

master -- ongoing development 2.2 -- stable maintenance

已创建功能分支feature(在下面的提交B处)并进行处理(B',C'和E'),并与源分支合并以拾取C和D

A feature branch feature was created (at commit B below) and worked on (B', C' & E') and merged against the source branch to pick up C and D

feature branch: B'-C'-C--D--E' / / source branch: A--B--C--D--E-- ...

现在,我想将feature合并回其源中,但是我不确定它最初是master还是2.2的分支.为了将功能合并到正确的源中,是否有一种编程方式来找出源分支是master还是2.2?

Now I want to merge feature back into its source, but I am not sure whether it was originally a branch off master or 2.2. In order to merge the feature into the correct source, is there a programmatic way to find out if source branch is master or 2.2?

推荐答案

Git仅跟踪单个存储库中的上游"信息,并且该信息不是静态的,也不在同一存储库的各个克隆之间共享.

Git only tracks "upstream" information in individual repositories and this information is not static nor shared between separate clones of the same repository.

从命令行设置此关系的命令是:

The command to set this relationship from the command line is:

git branch --set-upstream <branch> [<start-point>]

查看git-diff的输出可能会为您提供线索:

Looking at the output of git-diff might give you a clue:

git diff <mybranch>..master # commits in master that are not in mybranch git diff <mybranch>..2.2 # commits in 2.2 that are not in mybranch

列出的提交次数可能较少的是分支点(但是显然并不能保证.

It is likely that the one with fewer commits listed is the branch point (but that is not guaranteed, obviously.

您还可以使用gitk或git log进行浏览:

You can also use gitk, or git log to take a look around:

gitk --all git log --graph --color --decorate --oneline --all

更多推荐

如何确定特定分支的源分支?

本文发布于:2023-08-07 19:47:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!