查找哪个分支用于在Git中创建当前分支? [英] Find which branch is used to create current branch in Git?
问题描述
我如何知道哪个分支是另一个人创建的新分支的根源?可以基于当前HEAD创建新的分支,但也可以指定< start-point>
,它可以是提交,标记或分支。如何找出哪个分支用于创建新的分支?
一个奖金问题:提交可以与分支创建一起推送。我想通过在服务器上使用post接收挂钩来记录与新分支有关的提交。钩子是通过(oldrev,newrev,refname)传递的,如果我能找到上面我的问题的答案会很好。
解决方案有几种方法可以为一组分支找到共同的祖先提交。在问题中有几个答案:分支长度:分支在哪里在Git中开始?。
一个答案(它是我的一个答案)是使用 show-branch
命令,传入作为您想要比较的分支列表的参数,并找到共同的祖先提交。以下是来自 Linux Kernel Git文档的示例 show-branch
$ git show-branch master修复mhf
* [master]添加'git show-branch'。
! [修复]将重置类型标志引入git reset
! [mhf]允许+ remote:localrefspec在读取时产生--force。
---
+ [mhf]允许+ remote:localrefspec在读取时产生--force。
+ [mhf〜1]拉多个头时使用git-octopus。
+ [修复]将重置类型标志引入git reset
+ [mhf〜2]git fetch --force。
+ [mhf〜3]使用.git / remote / origin,而不是.git / branches / origin。
+ [mhf〜4]让git pull和git fetch默认为原点
+ [mhf〜5]臭名昭着的'章鱼合并'
+ [mhf〜6]退还git -parse远程。
+ [mhf〜7]多头提取。
+ [mhf〜8]开始添加$ GIT_DIR /遥控器/支持。
* ++ [master]添加'git show-branch'。
在该例子中,正在比较 master
与修复
和 mhf
分支。把这个输出想象成一个表格,每个分支都有它自己的列,每个分支都有自己的行。包含提交的分支将在该提交的行的列中显示 +
或 -
。 / p>
在输出的最底部,您会看到所有3个分支共享一个共同的祖先提交,并且它实际上是 这意味着头
在 master : + [master]添加'git show-branch'。
修正
和<$ code> mhf master
中分支。
I'm working on a project which is also worked on by a big team. As time passed by, people have been creating branches and pushing them to a remote repo.
How do I know which branch was the root of a new branch created by another person? New branches can be created based off of current HEAD, but one could also specify <start-point>
which can be a commit, a tag, or a branch. How do I find out which branch is used to create a new branch?
A bonus question: commits could be pushed along with a branch creation. I'd like to log those commits pertaining to the new branch by using a post receive hook on the server. The hook is passed with (oldrev, newrev, refname), it would be nice if I can find out answer to my question above.
There are several ways you can find a common ancestor commit for a group of branches. There are several answers in the question Branch length: where does a branch start in Git?.
One answer (it's one of mine) is to use the show-branch
command, passing in as arguments a list of branches that you want to compare and find a common ancestor commit for. Here's an example from the Linux Kernel Git documentation for show-branch
$ git show-branch master fixes mhf
* [master] Add 'git show-branch'.
! [fixes] Introduce "reset type" flag to "git reset"
! [mhf] Allow "+remote:local" refspec to cause --force when fetching.
---
+ [mhf] Allow "+remote:local" refspec to cause --force when fetching.
+ [mhf~1] Use git-octopus when pulling more than one heads.
+ [fixes] Introduce "reset type" flag to "git reset"
+ [mhf~2] "git fetch --force".
+ [mhf~3] Use .git/remote/origin, not .git/branches/origin.
+ [mhf~4] Make "git pull" and "git fetch" default to origin
+ [mhf~5] Infamous 'octopus merge'
+ [mhf~6] Retire git-parse-remote.
+ [mhf~7] Multi-head fetch.
+ [mhf~8] Start adding the $GIT_DIR/remotes/ support.
*++ [master] Add 'git show-branch'.
In that example, master
is being compared with the fixes
and mhf
branches. Think of this output as a table, with each branch getting it's own column, and each commit getting its own row. Branches that contain a commit will have a +
or -
show up in their column in the row for that commit.
At the very bottom of the output, you'll see that all 3 branches share a common ancestor commit, and that it is in fact the head
commit of master
:
*++ [master] Add 'git show-branch'.
This means that both fixes
and mhf
were branched off of that commit in master
.
这篇关于查找哪个分支用于在Git中创建当前分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!