找出什么时候创建了一个git分支(而不是第一次提交该分支) [英] find out when a git branch was created (not the first commit to that branch)

查看:104
本文介绍了找出什么时候创建了一个git分支(而不是第一次提交该分支)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能知道何时创建了一个git分支?



我不想知道什么时候第一次提交到该分支。
我想知道这个分支是在什么时候创建的。



这是一个重现实例的脚本:

 #! / bin / bash 
set -x
set -e

mkdir test
cd test
git init
echohello> readme
git add readme
git commit -m初始导入
日期

睡眠5
git结帐-b br1
日期#这是我想知道的日期。

sleep 5
echohello_br1> readme
git commit -a -mhello_br1
日期

echohello_br1_b > readme
git commit -a -mhello_br1_b

git checkout master
echohello_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
code>

执行此操作:

  ./test.sh 
++ set -e
++ mkdir test
++ cd test
++ git init
初始化的空的Git仓库/ test_git / test2 / .git /
++ echo hello
++ git add readme
++ git commit -m'初始导入'
[master(root-commit)9b95944] initial导入
1个文件已更改,1个插入(+),0个删除( - )
创建模式100644自述文件
++日期
8月16日星期五17:51:24 CEST 2013
++ sleep 5
++ git checkout -b br1
转换为新分支'br1'
++日期
8月16日星期五17:51:29 CEST 2013
++ sleep 5
++ echo hello_br1
++ git commit -a -m hello_br1
[br1 6c559cd] hello_br1
1个文件已更改,1个插入( +),1次删除( - )
++日期
8月16日星期五17:51:34 CEST 2013
++ echo hello_br1_b
++ git commit -a -m hello_br1_b
[br1 5f0d8ab] hello_br1_b
更改1个文件,1个插入(+),1个删除( - )
++ git checkout master
转换到分支'master'
++ echo hello_master
++ git commit -a -m hello_master
[master 2ed092d] hello_master
1个文件已更改,1个插入(+),1个删除( - )
++ 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导入

所以,使用git log或git reflog,我可以找出初始导入的日期(17:51:24)和第一次提交到分支br1(17:51:34)的日期。



但我需要找出分支br1被创建(17:51:29)。

如何做到这一点?



(奖金问题:并且,它是否具有散列?如何知道是谁创建了该分支)

解决方案

抱歉,Git没有正式保存跟踪创建分支的时间信息(它不是存储和在库之间共享的数据)。分支仅仅是提交的引用,仅此而已。这也意味着没有任何id或对象会指向你这个数据。



reflog记录对分支进行更改的时间,但它只是有限的历史随着时间的推移而过期。它确实记录了一些信息。例如, git branch bar 导致在reflog中输入:

  :: git reflog show --date = iso bar 
7d9b83d bar @ {2013-08-16 12:23:28 -0400}:分支:从master创建

使用 git checkout -b bar 时,我也会看到类似的条目:

  :: git co -b bar 
切换到新分支'bar'
:: git reflog show --date = iso bar
d6970ef bar @ {2013-08-16 12:30:50 -0400}:分支:从头创建

因此,根据您的使用情况以及您需要挖掘的距离, git reflog 可能实际上对您有用。 / p>

how can I know when a git branch was created?

i don't want to know when was the first commit to that branch. I want to find out when that branch was created.

This is a script to reproduce a working example:

#! /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

Executing this:

./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

so, with git log, or git reflog, I can find out the date of the initial import (17:51:24) and the date of the first commit to the branch br1 (17:51:34).

but I need to find out when the branch br1 was created (17:51:29).

how to do that?

(bonus question: and, does it have a hash? how to know who created that branch)

解决方案

Sorry, but Git doesn't keep officially tracked information of when branches are created (it's not data that stored and shared among repositories). Branches are simply references to commits and nothing more. This also means that there is no id or object that will point you at this data.

The reflog does keep track of when changes are made to a branch, but it's only a limited history that expires over time. It does record some information though. For instance, git branch bar resulted in this entry in the reflog:

:: git reflog show --date=iso bar
7d9b83d bar@{2013-08-16 12:23:28 -0400}: branch: Created from master

I also see a similar entry when using git checkout -b bar:

:: git co -b bar
Switched to a new branch 'bar'
:: git reflog show --date=iso bar
d6970ef bar@{2013-08-16 12:30:50 -0400}: branch: Created from HEAD

So, depending on your use-case, and how far back you need to dig, git reflog may actually be useful for you.

这篇关于找出什么时候创建了一个git分支(而不是第一次提交该分支)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆