我在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更多推荐
如何确定特定分支的源分支?
发布评论