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


当前回答

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)

其他回答

试试这个

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

Use

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

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

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

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

我还不确定git命令,但我认为您可以在reflogs中找到它们。

.git/logs/refs/heads/<yourbranch>

我的文件中似乎有一个unix时间戳。

更新:在打印日志时,似乎有一个选项可以使用reflog历史而不是提交历史:

git log -g

您还可以跟踪此日志,回溯到创建分支的时候。Git日志显示的是提交的日期,而不是在reflog中创建条目的操作的日期。除了在上面的路径中查看实际的reflog之外,我还没有发现。

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

(源)

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

结合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