git 我从哪里分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9898093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where did I branch from?
提问by Marsellus Wallace
I got back on an old project and I ran the nice git status
to figure out what was going on and I noticed way too many branches! I want to do some housekeeping before starting to work on this again but I'm not sure which branch comes from which..
我回到了一个旧项目,我很好git status
地弄清楚发生了什么,我注意到太多的分支!我想在再次开始工作之前做一些家务,但我不确定哪个分支来自哪个..
E.G. Does "branchA" derive from "develop"? Does "branchB" derive from "master" or "branchA"??
EG “branchA”是否源自“develop”?“branchB”是从“master”还是“branchA”派生的??
How can I answer the sample questions above?
我如何回答上述示例问题?
采纳答案by Amber
There's no canonical answer for this, since branches are simply pointers to certain commits in a DAG. For instance, master
and foo
could be pointing at the same commit; if you then create a branch from foo
, it's effectively the same as creating a branch from master
.
对此没有规范的答案,因为分支只是指向 DAG 中某些提交的指针。例如,master
并且foo
可能指向同一个提交;如果然后从 中创建一个分支foo
,它实际上与从 中创建一个分支相同master
。
That said, if you visualize the commit graph (via gitk
or some other graphical history tool), you can get a general sense of where the branch points are in the commit graph, versus where various branch pointers are pointing.
也就是说,如果您将提交图可视化(通过gitk
或其他一些图形历史工具),您可以大致了解分支点在提交图中的位置,以及各种分支指针所指向的位置。
回答by patthoyts
git merge-baseshows the commit that is the common ancestor of two branches.
git merge-base显示作为两个分支的共同祖先的提交。
Simple usage: git merge-base <branch> <branch>
shows the common commit of the two branches.
简单用法:git merge-base <branch> <branch>
显示两个分支的共同提交。
回答by Cory Klein
If you are already on a branch then you can get the commit that is the point where it forked from another branch, say master
, like this:
如果您已经在一个分支上,那么您可以获得提交,这是它从另一个分支分叉的点,例如master
,如下所示:
git merge-base --fork-point master
Then fetch the commit message with git show <commit-id>
.
If you got no commit ids then this branch did not come from that.
然后使用 获取提交消息git show <commit-id>
。如果你没有提交 ID,那么这个分支就不是来自那个分支。
For example I'm not sure if I forked from dev
or master
:
例如,我不确定我是否从dev
或分叉master
:
$ git checkout my-branch
$ git merge-base --fork-point master
$ git merge-base --fork-point dev
1770f75fa178df89a40ddc5f13ecd6bc597c17df
$ git show 1770f75fa178df89a40ddc5f13ecd6bc597c17df
commit 1770f75fa178df89a40ddc5f13ecd6bc597c17df (origin/popup-stack-12, dev)
Merge: 37f79cf f8a9795
Author: Superman <[email protected]>
Date: Sun Mar 29 23:14:40 2020 +0000
...
I forked this branch from dev.
我从 dev 分叉了这个分支。
回答by Mario Frai?
If you are working on Windows or Linux (with GUI), just install the beautiful git-extensions. They can visualize you the branch / merges tree perfectly fine.
如果您在 Windows 或 Linux(使用 GUI)上工作,只需安装漂亮的 git-extensions。他们可以完美地将分支/合并树形象化。
http://code.google.com/p/gitextensions/downloads/detail?name=GitExtensions207.zip&can=4&q=
http://code.google.com/p/gitextensions/downloads/detail?name=GitExtensions207.zip&can=4&q=
Greetings,
你好,
回答by Walt Howard
The command line git executable also has the ability to display a rudimentary tree of branching and merging, use the --graph option to git log. You can do all sorts of nice enhancements to it with the other options. Try these on for size:
命令行 git 可执行文件还具有显示分支和合并的基本树的能力,使用 --graph 选项来 git log。您可以使用其他选项对其进行各种不错的改进。试试这些尺寸:
simplest: git log --graph
最简单: git log --graph
nice: git log --graph --decorate --simplify-by-decoration --color --oneline --date=local
不错: git log --graph --decorate --simplify-by-decoration --color --oneline --date=local
the full monty: git log --graph --decorate --simplify-by-decoration --color --oneline --date=local --pretty=format:'%C(auto) %h %d %C(reset)%s (%C(cyan)%ad %ae%C(reset))'
完整的蒙蒂: git log --graph --decorate --simplify-by-decoration --color --oneline --date=local --pretty=format:'%C(auto) %h %d %C(reset )%s (%C(青色)%ad %ae%C(reset))'
回答by Not_a_Golfer
You can use a graphical tree viewer, I'm using gitg
to view branches and diffs, although I'm using the command line for the real work most of the time.
您可以使用图形树查看器,我正在使用它gitg
来查看分支和差异,尽管我大部分时间使用命令行进行实际工作。
回答by Basil Musa
Stick to a naming convention and spare yourself all the confusion.
坚持命名约定,避免所有的混乱。
When creating a branch from master
- lets say, to implement an email feature - you can name it master_emailfeature
. Then if you need to create a sub-branch from this branch to implement ssl for emails then you can name it master_emailfeature_sslandtls
.
当创建一个分支时master
——比如说,为了实现一个电子邮件功能——你可以将它命名为master_emailfeature
. 然后,如果您需要从该分支创建一个子分支来实现电子邮件的 ssl,那么您可以将其命名为master_emailfeature_sslandtls
.
This makes it clear which branch was created from which just by looking at the branch's name.
只需查看分支的名称,就可以清楚地知道哪个分支是从哪个分支创建的。
回答by Jake Levsen
If you want to figure out which remote branch your local branch derived from, this command can shed some light.
如果你想弄清楚你的本地分支来自哪个远程分支,这个命令可以说明一些问题。
git remote show origin
Scroll down until you see "Local branches configured for 'git pull':" and underneath that, a list of all your local branches are displayed and the remote branch each will merge with.
向下滚动,直到看到“为 'git pull' 配置的本地分支:”,在其下方,将显示所有本地分支的列表,并且每个远程分支都将与之合并。