[英]Force git log to show all commits, including cherry-picked
在寫作時,我剛剛找到了這個問題的答案,但仍然會發布它與他人分享。
我創建了一個合並了兩個分支的小型測試存儲庫,其中一個分支包含另一個分支中已經存在的精選版本的提交。
(我使用rebase -ir
人為地制作了這個測試歷史)
常規 git 日志顯示完整的歷史記錄:
> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8
* b1008ab1 (HEAD -> master) Merge 'alternative' into master.
|\
| * 22a3a296 Add x.txt
| * 0af2f788 Add y.txt
* | 3856adbf Add y.txt
* | 8543e6d8 Add x.txt
|/
* e7696150 Initial commit.
(我為此使用git lol
別名,但對於這個問題,我正在拼寫所有選項)
但是,過濾到其中一個文件的 git 日志僅顯示分支主要部分中的一個相應提交(第一個合並父級):
> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 x.txt
* 8543e6d8 Add x.txt
如何強制 git 日志顯示修改相應文件的所有提交,包括重復/精選提交?
我檢查了git help log
,發現--cherry-mark
、 --cherry-pick
、 --left-only
、 --right- --right-only
,但這些都沒有真正的區別。
使用git log --full-history --simplify-merges
!
--full-history
已經做了你想要的,但它列出了很多提供很少信息的合並。
添加--simplify-merges
隱藏其中一些合並。
詳細解釋請查看git help log
。
如果提供了路徑,這只會產生影響。 如果沒有提供路徑,它已經顯示了所有精心挑選的提交。
> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- x.txt
* 8543e6d8 Add x.txt
> git log --simplify-merges --full-history --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- x.txt
* 0de2139f (HEAD -> master) Merge 'alternative' into master.
|\
| * 22a3a296 Add x.txt
* 8543e6d8 Add x.txt
有趣的是,這條路徑也可以是全局通配符。
> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- *
* 2c970073 Add z.txt
* 22a3a296 Add x.txt
* 0af2f788 Add y.txt
* e7696150 (tag: BEGIN) Add a jpg image
> git log --simplify-merges --full-history --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- *
* 0de2139f (HEAD -> master) Merge 'alternative' into master.
|\
| * 2c970073 Add z.txt
| * 22a3a296 Add x.txt
| * 0af2f788 Add y.txt
* | 3856adbf Add y.txt
* | 8543e6d8 Add x.txt
|/
* e7696150 (tag: BEGIN) Add a jpg image
我發現git log
在具有復雜歷史記錄的大型倉庫中使用--full-history
和--simplify-merges
merges 慢得多。
如果指定了提交范圍,例如git log <parameters> master..develop -- <path>
,那么即使使用--simplify-merges
。
這些參數與--graph
參數結合使用很有用。 我已經有了這個作為lol
和lola
的別名(有些博客文章是人們提出這些名字的,我沒有發明它們)。
所以我現在將它添加到我的全局 git 配置中:
[alias]
lol = log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8
lola = log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 --all
lolf = log --graph --decorate --pretty=oneline --abbrev-commit --full-history --simplify-merges --abbrev=8
lolaf = log --graph --decorate --pretty=oneline --abbrev-commit --full-history --simplify-merges --abbrev=8 --all
也許不是。 檢查下面 torek 的評論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.