How to determine when a Git branch was created?

2019-01-04 04:53发布

Is there a way to determine when a Git branch was created? I have a branch in my repo and and I don't remember creating it and thought maybe seeing the creation timestamp would jog my memory.

8条回答
做自己的国王
2楼-- · 2019-01-04 05:45

Try this

  git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)'
查看更多
聊天终结者
3楼-- · 2019-01-04 05:47

First, if you branch was created within gc.reflogexpire days (default 90 days, i.e. around 3 months), you can use git log -g <branch> or git reflog show <branch> to find first entry in reflog, which would be creation event, and looks something like below (for git log -g):

Reflog: <branch>@{<nn>} (C R Eator <creator@example.com>)
Reflog message: branch: Created from <some other branch>

You would get who created a branch, how many operations ago, and from which branch (well, it might be just "Created from HEAD", which doesn't help much).

That is what MikeSep said in his answer.


Second, if you have branch for longer than gc.reflogexpire and you have run git gc (or it was run automatically), you would have to find common ancestor with the branch it was created from. Take a look at config file, perhaps there is branch.<branchname>.merge entry, which would tell you what branch this one is based on.

If you know that the branch in question was created off master branch (forking from master branch), for example, you can use the following command to see common ancestor:

git show $(git merge-base <branch> master)

You can also try git show-branch <branch> master, as an alternative.

This is what gbacon said in his response.

查看更多
登录 后发表回答