我如何知道何时创建了一个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
Run Code Online (Sandbox Code Playgroud)
执行此:
./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
Run Code Online (Sandbox Code Playgroud)
所以,使用git log或git reflog,我可以找到初始导入的日期(17:51:24)和第一次提交到分支br1的日期(17:51:34).
但是我需要找出分支br1何时被创建(17:51:29).
怎么做?
(奖金问题:并且,它是否有哈希?如何知道谁创建了该分支)
Joh*_*ter 30
很抱歉,但Git没有保留正式跟踪的创建分支的信息(这不是存储库之间存储和共享的数据).分支只是对提交的引用,仅此而已.这也意味着没有id或对象可以指向此数据.
reflog会跟踪对分支进行更改的时间,但它只是一段有限的历史记录,随着时间的推移而过期.它确实记录了一些信息.例如,git branch bar在reflog中导致了这个条目:
:: git reflog show --date=iso bar
7d9b83d bar@{2013-08-16 12:23:28 -0400}: branch: Created from master
Run Code Online (Sandbox Code Playgroud)
使用时我也看到类似的条目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
Run Code Online (Sandbox Code Playgroud)
因此,根据您的使用情况,以及您需要挖掘的距离,git reflog实际上可能对您有用.
你既不知道是谁创建了分支,也不知道它是什么时候创建的 - 至少不是Git本身.
因为Git不跟踪分支元数据.它根本不关心谁创建了一个分支(你通常从远程控制器获得很多分支),因为分支只是提交的指针(refs).
因此,一个分支也并没有有一个分支-一个Git裁判是的,其实,你在一个简单的纯文本文件.git夹包含它所引用的对象(或者的哈希在一个象征性的裁判,其他的名字的情况下,参考参考).
| 归档时间: |
|
| 查看次数: |
36852 次 |
| 最近记录: |