如何知道 Git 分支是何时创建的?
我不想知道该分支的第一次提交是什么时候,我想找出该分支创建的时间。
这是一个用于重现工作示例的脚本:
#! /bin/bash
set -x
set -e
mkdir test
cd test
git init
echo "hello" >readme
git add readme
git commit -m "initial import"
date
sleep 5
git checkout -b br1
date # this is the date that I want to find out.
sleep 5
echo "hello_br1" >readme
git commit -a -m "hello_br1"
date
echo "hello_br1_b" >readme
git commit -a -m "hello_br1_b"
git checkout master
echo "hello_master" >readme
git commit -a -m "hello_master"
git branch -a;
git log --all --graph --abbrev-commit --decorate --pretty=format:"%h - %an, %ad : %s" --date=iso
执行这个操作:
./test.sh
++ set -e
++ mkdir test
++ cd test
++ git init
Initialized empty Git repository in /test_git/test2/.git/
++ echo hello
++ git add readme
++ git commit -m 'initial import'
[master (root-commit) 9b95944] initial import
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 readme
++ date
Fri Aug 16 17:51:24 CEST 2013
++ sleep 5
++ git checkout -b br1
Switched to a new branch 'br1'
++ date
Fri Aug 16 17:51:29 CEST 2013
++ sleep 5
++ echo hello_br1
++ git commit -a -m hello_br1
[br1 6c559cd] hello_br1
1 files changed, 1 insertions(+), 1 deletions(-)
++ date
Fri Aug 16 17:51:34 CEST 2013
++ echo hello_br1_b
++ git commit -a -m hello_br1_b
[br1 5f0d8ab] hello_br1_b
1 files changed, 1 insertions(+), 1 deletions(-)
++ git checkout master
Switched to branch 'master'
++ echo hello_master
++ git commit -a -m hello_master
[master 2ed092d] hello_master
1 files changed, 1 insertions(+), 1 deletions(-)
++ git branch -a
br1
* master
++ git log --all --graph --abbrev-commit --decorate '--pretty=format:%h - %an, %ad : %s' --date=iso
* 5f0d8ab - David Portabella, 2013-08-16 17:51:34 +0200 : hello_br1_b
* 6c559cd - David Portabella, 2013-08-16 17:51:34 +0200 : hello_br1
| * 2ed092d - David Portabella, 2013-08-16 17:51:34 +0200 : hello_master
|/
* 9b95944 - David Portabella, 2013-08-16 17:51:24 +0200 : initial import
因此,使用git log或git reflog,我可以找到初始导入的日期(17:51:24)以及第一次提交到分支br1的日期(17:51:34)。
但是我需要查找分支br1创建的时间(17:51:29)。
如何做到这一点?
(奖励问题:它是否有哈希值?如何知道谁创建了该分支)