是否有一种方法可以确定Git分支是何时创建的?我在我的repo中有一个分支,我不记得创建了它,我想也许看到创建时间戳会唤醒我的记忆。


当前回答

Pro Git§3.1 Git分支-什么是分支有一个很好的解释什么是Git分支

Git中的分支只是一个轻量级的指向[A]提交的移动指针。

由于分支只是一个轻量级指针,git没有明确的历史或创建日期的概念。“但是等一下,”我听到你说,“git当然知道我的分支历史!”嗯,算是吧。

如果您运行以下任一项:

git log <branch> --not master
gitk <branch> --not master

你会看到看起来像“你的分支的历史记录”,但实际上是一个从“分支”可以到达的提交列表,而从master不能到达。这为你提供了你想要的信息,但当且仅当你从未将'branch'合并回master,并且自创建以来从未将' master '合并到'branch'。如果你们已经合并,那么这段分歧的历史就会崩溃。

幸运的是,reflog通常包含您想要的信息,正如这里的各种其他答案所解释的那样。用这个:

git reflog --date=local <branch>

以显示分支的历史。该列表中的最后一个条目(可能)是您创建分支的点。

如果分支已经被删除,那么'branch'不再是一个有效的git标识符,但你可以使用这个来代替,它可能会找到你想要的:

git reflog --date=local | grep <branch>

或者在Windows cmd shell中:

git reflog --date=local | find "<branch>"

请注意,reflog不能在远程分支上有效工作,只能在您在本地工作过的分支上有效工作。

其他回答

Use:

git reflog

在当前文件夹中显示存储库的所有生命周期。 首先出现的分支名称(从下到上)是创建的源。

855a3ce HEAD@{0}: checkout: moving from development to feature-sut-46
855a3ce HEAD@{1}: checkout: moving from feature-sut-46 to development
855a3ce HEAD@{2}: checkout: moving from feature-jira35 to feature-sut-46
535dd9d HEAD@{3}: checkout: moving from feature-sut-46 to feature-jira35
855a3ce HEAD@{4}: checkout: moving from development to feature-sut-46
855a3ce HEAD@{5}: checkout: moving from feature-jira35 to development
535dd9d HEAD@{6}: commit: insert the format for vendor specific brower - screen.css
855a3ce HEAD@{7}: checkout: moving from development to feature-jira35
855a3ce HEAD@{8}: checkout: moving from master to development

这意味着:

从master创建分支开发(checkout -b) 分支feature-jira35从开发中创建(checkout -b) 分支特性-jira-sut-46从开发中创建(签出-b)

如果只是检查原始修订的SHA1:

(源)

可以简化和使用git日志-一线主..修复

Use

git show --summary `git merge-base foo master`

如果您更愿意使用gitk在上下文中查看它,那么使用

gitk --all --select-commit=`git merge-base foo master`

(foo是你要找的分支的名称。)

试试这个

  git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)'

结合Andrew Sohn的回答(https://stackoverflow.com/a/14265207/1929406)

branchcreated=$(git reflog show --date=format:'%Y-%m-%d %H:%M:%S' --all | sed 's!^.*refs/!refs/!' | grep '/master' | tail -1| cut -d'{' -f 2| cut -d'}' -f 1 | xargs)
echo $branchcreated