I want to know the time of a branch's creation. And i can't use 'git reflog' because the branch was just checked out from remote. So locally there are only reflogs of my checkout. I use git log and got plenty of logs including other branches. How can I get the time?
-
`git log -g
or git reflog show – Ivan Sheihets Jul 05 '18 at 11:25` -
@IvanSheigets I could not find a doc reference for `git log -g`, are you sure this works? A branch is just a reference to a commit. Since a newly created branch points to the same commit as some other branch, created at a different time, does a branch "know" when it was created? – Tim Biegeleisen Jul 05 '18 at 11:31
-
1@Tim Biegeleisen, it works – Ivan Sheihets Jul 05 '18 at 11:35
-
@IvanSheigets If I developes the branch myselves by my own PC, it works. But for a branch from remote it can't. I can only get logs of the branch after the time i pulled it without the ealier logs. – soda Jul 05 '18 at 11:48
-
Please review https://stackoverflow.com/questions/2255416/how-to-determine-when-a-git-branch-was-created, It may help you. – Darpan Chhatravala Jul 05 '18 at 14:11
1 Answers
git does not keep track of the time a branch was created. The closest you can come is, if you make certain assumptions about commit topology, you can check the date(s) from the first commit that appears to relate to the branch.
Suppose you have
x -- o -- x -- x <--(master)
\
A -- B -- c <--(feature)
Now it may seem "obvious" that feature
was created at o
, and then A
was committed to feature
(followed by B
and C
). It's not necessarily true, and git doesn't track any information that will tell you if it's true, because in git a branch is just a pointer to a single commit (with a convention that it usually moves in a certain way as commits are added). In this case feature
points to C
, and that's all we're sure to know about feature
.
(We might also know how the branch has moved locally - but only if it has moved locally. We might also know something about relating the branch to a remote, and I guess you could try to extract information from the remote... but it generally doesn't know when the branch was created either.)
But intuitively many people think of feature
as comprising commits A
, B
, and C
(and possibly having a life of its own that started at o
). In some tools that would be accurate; it just isn't the case in git.
So you could use either committer dates or author dates of commits, depending on what you're trying to understand. Here are some ways to look at it:
You could use A
s author date. If the branch is rebased, this should remain the same and at that point may precede the author date of its parent; so this won't necessarily tell you when the topological branch point could first be found at o
, but it will give a fair estimate of when development for the branch started. You could find this value as
git rev-list --format=%ad master..feature |tail -n1
If you can rule out rebasing, then you could estimate that development began sometime before A
s author date, and sometime after o
s author date. You can get o
s author date as
git rev-list --format=%ad -n1 $(git merge-base master feature)
In either case, you could use commit dates instead of author dates; but in that case, be aware that rebasing feature
creates new commits (A'
instead of A
, etc.) and so commit dates are changed. So if you want to know when development started, this is less reliable; but if you want to know when the topological branch point appeared at o
, it is perhaps more reliable. You'd use %cd
in place of %ad
from the above commands.

- 42,148
- 4
- 35
- 52
-
Related: https://stackoverflow.com/a/3162929/1256452 (probably worth linking to the question, this one is the rather nice answer). – torek Jul 05 '18 at 18:59
-
Thank you for the answer, it helps a lot. At the end I used 'git log --graph' to find out the last 'merge master' of the branch and determine that time as the branch's creating time. It's not exact but can reach my goal. – soda Jul 06 '18 at 07:07