2013-08-16 95 views
5

我怎麼能知道什麼時候創建了一個git分支?找出什麼時候創建了一個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的日誌,或混帳引用日誌,我可以找出最初的日子導入(17:51:24)和第一次提交到分支br1(17:51:34)的日期。

但我需要找出什麼時候創建分支br1(17:51:29)。

該怎麼辦?

(獎金問題:和,它有一個哈希如何知道是誰創建的分支?)

+0

另請參見(1)[尋找兩個分支的共同祖先](http://stackoverflow.com/questions/1549146/find-common-ancestor-of-two-branches),(2)[尋找分支點與Git?](http://stackoverflow.com/questions/1527234/finding-a-branch-point-with-git)和(3)[分支長度:分支在Git中開始?](http: //stackoverflow.com/questions/17581026/branch-length-where-does-a-branch-start-in-git)。 – 2013-08-16 16:51:43

+0

[如何確定何時創建Git分支?](http:// stackoverflow。com/questions/2255416/how-to-determine-when-a-git-branch-was-created) –

回答

19

對不起,但是Git沒有正式跟蹤創建分支的時間信息(它不是在存儲庫之間存儲和共享的數據)。分支僅僅是提交的引用,僅此而已。這也意味着沒有id或對象會指向你這個數據。

reflog確實記錄對某個分支進行更改的時間,但這只是一個有限的歷史記錄,會隨着時間的推移而過期。它確實記錄了一些信息。例如,git branch bar導致了reflog了此項:

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

我也看到了類似的條目使用時git checkout -b bar

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

所以,這取決於你的使用情況,以及如何追溯你需要挖掘,git reflog可能實際上對你有用。

+0

這個命令確實顯示了我需要的信息(至少是日期),謝謝。可惜它不存儲這個信息officialy,並永遠。爲什麼它不會那樣做?爲什麼有人會認爲知道誰創建了一個分支以及何時創建並不重要?無論如何,你知道一個技巧來爲遠程倉庫做同樣的事嗎? (當我想知道是誰在遠程存儲庫中創建了一個分支時,這個技巧不起作用) –

+2

不幸的是,我不認爲我們在遠程回購上有相同的技巧。 reflog是本地的回購。在遠程端,您可能會看到正在創建的分支,但是作爲推送的一部分,並且會有該時間戳(而不是作者創建它的時間戳)。至於爲什麼Git沒有跟蹤這一點,最近在git郵件列表上討論了它,所以我不會重複它。我會挖掘一個鏈接並在稍後發佈(我現在必須馬上運行)。簡而言之:他們認爲它不足以保留。 – jszakmeister

7

你既不能查出是誰創造了一個分支,也不是當它被創造的 - 至少沒有使用Git本身。因爲Git不跟蹤分支元數據。它根本不在乎誰做了一個分支(你通常從遠程獲得很多分支),因爲分支只是指向提交的指針(參考)。

這樣一個部門也確實沒有一個分支 - 一個Git裁判是的,其實,在你.git文件夾中包含它引用的對象(或者的哈希在一個象徵性的情況下,一個簡單的純文本文件ref,它引用的另一個ref的名稱)。

相關問題