簡體   English   中英

僅查看某些分支的git log(帶合並)

[英]View git log (with merges) for only certain branches

我知道如何僅使用--first-parent查看特定分支的日志,如下所示:

git log --oneline --graph --first-parent origin/master origin/topic1

這個問題是我沒有看到指定的那些分支之間的合並關系(這就是我想要的)。 如果我這樣做:

git log --oneline --graph origin/master origin/topic1

無論如何它會顯示所有分支,即使我已經指定我只想看到其中的兩個。

我想要的是能夠指定特定的分支來查看日志, 看到只有那些分支之間的合並。 我需要這個的原因是因為有很多其他長壽命的分支導致圖形變大,我必須滾動幾個頁面才能找到分支關系。 我需要一種方法來過濾掉它們。

這可能嗎?

編輯

這是我的實際別名:

short-log-base = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset)%x09%C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim white)%an%C(reset) - %C(white)%s%C(reset)'
lgs = !git short-log-base --first-parent

我做以下事情:

git lgs topic1 master

我意識到傳入兩個分支將顯示這兩者之間的提交,我真正希望它做的是向我展示這兩個分支以及它們之間的任何關系。 所有其他祖先都應該被忽略而不顯示。

當我運行上面的命令時,我沒有看到在發生合並提交的那兩個分支中的提交之間的圖形繪制線。

這里只是我的噩夢日志圖的一小部分示例(中間的一個片段):

| | | | | | | | | | | | | | | | | * 431ce45     (5 months ago)
| | | | | | | | | | | | | | | | | * 14a0211     (6 months ago)
| | | | | | | | | | | | | | | | | * 0afde13     (8 months ago)
| | | | | | | | | | | | | | | | | * 88872ab     (3 weeks ago)
| |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|/
|/| | | | | | | | | | | | | | | |
* | | | | | | | | | | | | | | | | f8f9efd       (3 weeks ago)
* | | | | | | | | | | | | | | | | a65759b       (3 weeks ago)
* | | | | | | | | | | | | | | | | 6814d25       (3 weeks ago)
* | | | | | | | | | | | | | | | | ca242b7       (3 weeks ago)
* | | | | | | | | | | | | | | | | d29f84c       (3 weeks ago)
* | | | | | | | | | | | | | | | | 3e91342       (3 weeks ago)
* | | | | | | | | | | | | | | | | 5b23641       (3 weeks ago)
* | | | | | | | | | | | | | | | | 0e5e598       (3 weeks ago)
* | | | | | | | | | | | | | | | | f40e924       (3 weeks ago)
* | | | | | | | | | | | | | | | | 3614c05       (3 weeks ago)
| | | | | | | | | | | | | | | | | * b0b8f66     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 5b9a183     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 591af91     (3 weeks ago)
| | | | | | | | | | | | | | | | | * a1e6896     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 9e12dc7     (3 weeks ago)
| | | | | | | | | | | | | | | | | * e7d4203     (3 weeks ago)
| | | | | | | | | | | | | | | | | * 5286952     (3 weeks ago)
| | | | | | | | | | | | | | | | | * a4e52b6     (4 weeks ago)
| | | | | | | | | | | | | | | | | * d1da806     (4 weeks ago)
| | | | | | | | | | | | | | | | | * 76b2174     (4 weeks ago)
| | | | | | | | | | | | | | | | | * 48b0687     (4 weeks ago)

我根本不知道為什么這么多分支被展示出來,就我而言,我只想看到兩個分支之間的圖形。 如果讓這個工作起來意味着限制歷史的長度,那么請通過各種方式告訴我如何做到這一點。

你沒有看到“額外”的分支機構

您看到其他分支的唯一原因是因為這些分支您在命令行中指定的分支的祖先 為了演示,這就是我的日志的樣子:

$ git log --oneline --graph --decorate master temp -14
* 458e836 (HEAD, master) Add narf.txt   <===== Here is master
*   03bbab7 Merge branch 'bar'
|\
| * a765ecc (bar) Add quack.txt         <===== Here is bar
| * 80efc7c Add moo.txt
* | b1bc4f1 Add junk
|/
| * acb480b (temp) Add stuff after merge commit <===== Here is temp
| *   1e4b626 Merge branch 'foo' into temp
| |\
| | * 06c40a1 (foo) Add even more junk          <===== Here is foo
| | * ea3ea46 Add foo.txt
| |/
| * e918c72 Add derp.txt
| * f1a74d8 Add lol.txt
| * c244486 Add foo.txt
|/
* 7c61796 Fix OS X Bash `workdir` alias for new terminal tabs

請注意,即使我只在命令行中指定了mastertemp ,也會顯示barfoo ,因為它們是其他分支的祖先,因此也是其歷史的一部分。

你可能不想使用--no-merges ...

此外,我不建議您使用--no-merges來嘗試可視化您的分支,因為您有時可能會無意中遺漏有關何時使用該標志進行分支之間的合並的重要信息。 為了演示,當我使用--no-merges時,這就是我上面顯示的圖形:

$ git log --oneline --graph --decorate --no-merges master temp -11
* 458e836 (HEAD, master) Add narf.txt  <===== Here is master
* a765ecc (bar) Add quack.txt          <===== Here is bar
* 80efc7c Add moo.txt
| * b1bc4f1 Add junk                   <===== Which branch does this belong to?
|/
| * acb480b (temp) Add stuff after merge commit  <===== Here is temp
| * 06c40a1 (foo) Add even more junk             <===== Here is foo
| * ea3ea46 Add foo.txt
| * e918c72 Add derp.txt
| * f1a74d8 Add lol.txt
| * c244486 Add foo.txt
|/
* 7c61796 Fix OS X Bash `workdir` alias for new terminal tabs

請注意,您現在無法判斷提交b1bc4f1 Add junk458e836 Add narf.txt的祖先458e836 Add narf.txt 看起來好像b1bc4f1 Add junk不是master的一部分,實際上它是。

首選--first-parent

如果您想簡化分支歷史可視化,我建議您使用--first-parent標志:

git log --oneline --graph --decorate --first-parent origin/master origin/topic1

這是我的圖形日志使用它而不是--no-merges

$ git log --oneline --graph --decorate --first-parent master temp -9
* 458e836 (HEAD, master) Add narf.txt  <===== Here is master
* 03bbab7 Merge branch 'bar'
* b1bc4f1 Add junk
| * acb480b (temp) Add stuff after merge commit  <===== Here is temp
| * 1e4b626 Merge branch 'foo' into temp
| * e918c72 Add derp.txt
| * f1a74d8 Add lol.txt
| * c244486 Add foo.txt
|/
* 7c61796 Fix OS X Bash `workdir` alias for new terminal tabs

這實際上准確地表示了所有分支的最終歷史記錄,同時還通過隱藏中間提交來簡化圖形。

試試git show-branch <list of branches>

這將只顯示那些分支,直到它們的合並點。 它在“每日GIT有20個命令或所以”指南中提到。

手冊頁中的示例顯示了三個分支:直到'---'的第一行是分支,顯示了它們將被標記在哪一列; 然后按照您在選項中給出的順序進行相關提交,並在其中包含關於提交的分支的標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM