本文翻译自:How to determine when a Git branch was created?
Is there a way to determine when a Git branch was created? 有没有办法确定何时创建Git分支? 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. 我在存储库中有一个分支,并且我不记得创建它了,并以为也许看到创建时间戳会影响我的记忆。
参考:https://stackoom.com/question/9Sjg/如何确定何时创建Git分支
This is something that I came up with before I found this thread. 这是我在找到该线程之前想到的。
git reflog show --date=local --all | sed 's!^.*refs/!refs/!' | grep '/master' | tail -1
git reflog show --date=local --all | sed 's!^.*refs/!refs/!' | grep 'branch:'
I'm not sure of the git command for it yet, but I think you can find them in the reflogs. 我还不确定git命令,但是我认为您可以在reflog中找到它们。
.git/logs/refs/heads/
My files appear to have a unix timestamp in them. 我的文件似乎在其中包含unix时间戳。
Update: There appears to be an option to use the reflog history instead of the commit history when printing the logs: 更新:在打印日志时,似乎可以选择使用reflog历史记录而不是commit历史记录:
git log -g
You can follow this log as well, back to when you created the branch. 您也可以遵循此日志,回到创建分支时。 git log
is showing the date of the commit, though, not the date when you made the action that made an entry in the reflog. git log
显示的是提交日期,而不是您在reflog中进行输入操作的日期。 I haven't found that yet except by looking in the actual reflog in the path above. 除了在上面的路径中查看实际的reflog之外,我还没有发现。
Use 使用
git show --summary `git merge-base foo master`
If you'd rather see it in context using gitk, then use 如果您希望使用gitk在上下文中看到它,请使用
gitk --all --select-commit=`git merge-base foo master`
(where foo is the name of the branch you are looking for.) (其中foo是您要查找的分支的名称。)
First, if you branch was created within gc.reflogexpire
days (default 90 days, ie around 3 months), you can use git log -g
or git reflog show
to find first entry in reflog, which would be creation event, and looks something like below (for git log -g
): 首先,如果您的分支是在gc.reflogexpire
天内创建的(默认为90天,即3个月左右),则可以使用git log -g
或git reflog show
在reflog中查找第一个条目,即创建事件,如下所示(对于git log -g
):
Reflog: @{} (C R Eator )
Reflog message: branch: Created from
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). 您将了解谁创建了一个分支,执行了多少次操作,以及从哪个分支创建了(嗯,它可能只是“从HEAD创建”,这没有多大帮助)。
That is what MikeSep said in his answer . 这就是MikeSep在回答中所说的 。
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. 其次,如果分支的时间超过gc.reflogexpire
并且您已经运行了git gc
(或者它是自动运行的),则必须与创建该分支的分支找到共同的祖先。 Take a look at config file, perhaps there is branch.
entry, which would tell you what branch this one is based on. 看一下配置文件,也许有branch.
条目,它将告诉您该分支基于哪个分支。
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: 例如,如果您知道所讨论的分支是在master分支之外创建的(从master分支分支),则可以使用以下命令查看公共祖先:
git show $(git merge-base master)
You can also try git show-branch
, as an alternative. 您也可以尝试使用git show-branch
来替代。
This is what gbacon said in his response . gbacon的回应就是这样说的 。
Pro Git § 3.1 Git Branching - What a Branch Is has a good explanation of what a git branch really is Pro Git§3.1 Git分支-什么是分支对git分支的真正含义有很好的解释
A branch in Git is simply a lightweight movable pointer to [a] commit. Git中的分支只是指向[a]提交的轻量级可移动指针。
Since a branch is just a lightweight pointer, git has no explicit notion of its history or creation date. 由于分支只是一个轻量级的指针,因此git对它的历史或创建日期没有明确的概念。 "But hang on," I hear you say, "of course git knows my branch history!" “但是等等,”我听到你说,“ git当然知道我的分支历史!” Well, sort of. 好吧,有点。
If you run either of the following: 如果您运行以下任何一项:
git log --not master
gitk --not master
you will see what looks like the "history of your branch", but is really a list of commits reachable from 'branch' that are not reachable from master. 您将看到看起来像“分支的历史记录”的内容,但实际上是“分支”可到达的提交列表,而主分支无法到达。 This gives you the information you want, but if and only if you have never merged 'branch' back to master, and have never merged master into 'branch' since you created it. 这会为您提供所需的信息,但前提是且仅当您从未将“分支”合并回母版,并且自创建以来从未将母版合并到“分支”中。 If you have merged, then this history of differences will collapse. 如果你已经合并了,那么这个差异会历史崩溃。
Fortunately the reflog often contains the information you want, as explained in various other answers here. 幸运的是,刷新日志通常包含您想要的信息,如此处其他各种答案所述。 Use this: 用这个:
git reflog --date=local
to show the history of the branch. 显示分支的历史。 The last entry in this list is (probably) the point at which you created the branch. 此列表中的最后一个条目(可能是)创建分支的点。
If the branch has been deleted then 'branch' is no longer a valid git identifier, but you can use this instead, which may find what you want: 如果分支已被删除,则“ branch”不再是有效的git标识符,但是您可以改用该标识符,它可以找到所需的内容:
git reflog --date=local | grep
Or in a Windows cmd shell: 或在Windows cmd shell中:
git reflog --date=local | find ""
Note that reflog won't work effectively on remote branches, only ones you have worked on locally. 请注意,reflog在远程分支上无法有效工作,只有您在本地工作过的分支才能有效。