GIT - Where did I branch from?

2019-02-16 03:54发布

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..

E.G. Does "branchA" derive from "develop"? Does "branchB" derive from "master" or "branchA"??

How can I answer the sample questions above?

7条回答
该账号已被封号
2楼-- · 2019-02-16 04:23

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.

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.

查看更多
3楼-- · 2019-02-16 04:29

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.

查看更多
狗以群分
4楼-- · 2019-02-16 04:30

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.

查看更多
beautiful°
5楼-- · 2019-02-16 04:36

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.

http://code.google.com/p/gitextensions/downloads/detail?name=GitExtensions207.zip&can=4&q=

Greetings,

查看更多
Bombasti
6楼-- · 2019-02-16 04:39

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.

This makes it clear which branch was created from which just by looking at the branch's name.

查看更多
迷人小祖宗
7楼-- · 2019-02-16 04:42

git merge-base shows the commit that is the common ancestor of two branches.

Simple usage: git merge-base <branch> <branch> shows the common commit of the two branches.

查看更多
登录 后发表回答