ฉันเคยเห็นหนังสือและบทความบางอย่างมีกราฟที่ดูน่ารักของกิ่งก้านและคอมมิท ฉันจะสร้างภาพประวัติศาสตร์ git ที่พิมพ์ได้คุณภาพสูงได้อย่างไร
ฉันเคยเห็นหนังสือและบทความบางอย่างมีกราฟที่ดูน่ารักของกิ่งก้านและคอมมิท ฉันจะสร้างภาพประวัติศาสตร์ git ที่พิมพ์ได้คุณภาพสูงได้อย่างไร
คำตอบ:
ปรับปรุง: คำตอบนี้ได้รับความสนใจมากกว่าที่สมควร มันถูกโพสต์ครั้งแรกเพราะฉันคิดว่ากราฟดูดีและพวกเขาสามารถวาดใน Illustrator สำหรับสิ่งพิมพ์ - และไม่มีทางออกที่ดีกว่า แต่ตอนนี้มีคำตอบสำหรับคำถามนี้ที่มีอยู่มากมายเช่นfracz 's, Jubobs ', หรือHarry Lee ! โปรดลงคะแนนเหล่านั้น !!
อัปเดต 2: ฉันโพสต์เวอร์ชันที่ปรับปรุงแล้วของคำตอบนี้ไปยังโทโพโลยีการแสดงผลสาขาในคำถามคอมไพล์เนื่องจากมันเหมาะสมกว่านั้น เวอร์ชันนั้นมี lg3ซึ่งจะแสดงทั้งข้อมูลผู้แต่งและผู้ติดต่อดังนั้นคุณควรตรวจสอบ ออกจากคำตอบนี้ด้วยเหตุผลทางประวัติศาสตร์ (& rep ฉันจะยอมรับ) เหตุผลแม้ว่าฉันอยากจะลบมันจริงๆ
2 ¢ของฉัน: ฉันมีนามแฝงสองตัวที่ปกติฉันโยนใน~/.gitconfigไฟล์ของฉัน:
[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
git lg/ git lg1ดูเหมือนว่านี้:

และgit lg2มีลักษณะเช่นนี้:

#202020/ #555555แดง: #5d1a14/ #da4939สีเขียว: #424e24/ #a5c261เหลือง: #6f5028/ #ffc66dสีฟ้า: #263e4e/ #6d9cbeม่วง: #3e1f50/ #a256c7ฟ้า: #234e3f/ #62c1a1และสีขาว: /#979797 #ffffff
                    --date=relativeและ--abbrev-commitซ้ำซ้อนเพราะคุณใช้อย่างชัดเจน%crและ%hตามลำดับ
                    %C(auto)โมดิฟายเออร์ใน refname ( %d) เพื่อให้ได้สีที่ดีกว่า ดูstackoverflow.com/questions/5889878/color-in-git-log/ ......
                    lg = log --graph --abbrev-commit --decorate --format=format:'%C(yellow)%h%C(reset)%C(auto)%d%C(reset) %C(normal)%s%C(reset) %C(dim white)%an%C(reset) %C(dim blue)(%ar)%C     (reset)' --all
                    คำตอบมากมายที่นี่ยอดเยี่ยม แต่สำหรับผู้ที่ต้องการเพียงหนึ่งบรรทัดต่อคำตอบที่ง่ายโดยไม่ต้องตั้งค่านามแฝงหรืออะไรเพิ่มเติมนี่คือ:
git log --all --decorate --oneline --graph
ไม่ใช่ทุกคนที่จะทำgit logตลอดเวลา แต่เมื่อคุณต้องการเพียงจำ:
" A Dog " = บันทึกการคอมไพล์ - a - d - ecorate - o neline - g raph
git config --global alias.adog "log --all --decorate --oneline --graph"
                    --allเวลานานฉันกำลังจะร้องไห้ (T_T) ขอบคุณ!
                    สำหรับเอาต์พุตแบบข้อความคุณสามารถลอง:
git log --graph --abbrev-commit --decorate --date=relative --all
หรือ:
git log --graph --oneline --decorate --all
หรือ: นี่คือ นามแฝงกราฟวิซสำหรับการวาดกราฟ DAG
--abbrev-commit --decorateแล้วมันสมบูรณ์แบบ!
                    --abbrev-commitถ้าคุณใช้--oneline
                    git log --graph --oneline --decorate --date=relative --allการ--dateโต้แย้งไม่มีประโยชน์ ฉันไม่เห็นวันที่ที่แสดงในบันทึก
                    Gitgraph.jsอนุญาตให้วาดกิ่ง git ที่สวยโดยไม่มีที่เก็บ เพียงแค่เขียนรหัส Javascript ที่กำหนดค่าสาขาของคุณและกระทำและแสดงในเบราว์เซอร์
var gitGraph = new GitGraph({
   template: "blackarrow",
   mode: "compact",
   orientation: "horizontal",
   reverseArrow: true
});
var master = gitGraph.branch("master").commit().commit();
var develop = gitGraph.branch("develop").commit();
master.commit();
develop.commit().commit();
develop.merge(master);
หรือกับmetroแม่แบบ:

หรือด้วยการส่งข้อความผู้เขียนและแท็ก:

สร้างด้วยGit Grapherโดย @bsara
สร้างขึ้นบนTikZ & PGF , gitdagsเป็นแพคเกจน้ำยางเล็ก ๆ น้อย ๆ ที่ช่วยให้คุณได้อย่างง่ายดายผลิตเวกเตอร์กราฟิกกระทำกราฟและอื่น ๆ อีกมากมาย
รุ่นอัตโนมัติของพื้นที่เก็บข้อมูลที่มีอยู่กระทำกราฟไม่ได้วัตถุประสงค์ของgitdags; กราฟที่สร้างขึ้นมีวัตถุประสงค์เพื่อการศึกษาเท่านั้น
ฉันมักจะใช้มันเพื่อสร้างกราฟสำหรับคำตอบของคำถาม Git ซึ่งเป็นทางเลือกสำหรับ ASCII ที่ทำกราฟ:
นี่คือตัวอย่างของกราฟที่แสดงให้เห็นถึงผลกระทบของการเรียบง่าย:

\documentclass{article}
\usepackage{subcaption}
\usepackage{gitdags}
\begin{document}
\begin{figure}
  \begin{subfigure}[b]{\textwidth}
    \centering
    \begin{tikzpicture}
      % Commit DAG
      \gitDAG[grow right sep = 2em]{
        A -- B -- { 
          C,
          D -- E,
        }
      };
      % Tag reference
      \gittag
        [v0p1]       % node name
        {v0.1}       % node text
        {above=of A} % node placement
        {A}          % target
      % Remote branch
      \gitremotebranch
        [origmaster]    % node name
        {origin/master} % node text
        {above=of C}    % node placement
        {C}             % target
      % Branch
      \gitbranch
        {master}     % node name and text 
        {above=of E} % node placement
        {E}          % target
      % HEAD reference
      \gitHEAD
        {above=of master} % node placement
        {master}          % target
    \end{tikzpicture}
    \subcaption{Before\ldots}
  \end{subfigure}
  \begin{subfigure}[b]{\textwidth}
    \centering
    \begin{tikzpicture}
      \gitDAG[grow right sep = 2em]{
        A -- B -- { 
          C -- D' -- E',
          {[nodes=unreachable] D -- E },
        }
      };
      % Tag reference
      \gittag
        [v0p1]       % node name
        {v0.1}       % node text
        {above=of A} % node placement
        {A}          % target
      % Remote branch
      \gitremotebranch
        [origmaster]    % node name
        {origin/master} % node text
        {above=of C}    % node placement
        {C}             % target
      % Branch
      \gitbranch
        {master}      % node name and text 
        {above=of E'} % node placement
        {E'}          % target
      % HEAD reference
      \gitHEAD
        {above=of master} % node placement
        {master}          % target
    \end{tikzpicture}
    \subcaption{\ldots{} and after \texttt{git rebase origin/master}}
  \end{subfigure}
  \caption{Demonstrating a typical \texttt{rebase}}
\end{figure}
\end{document}:)
                    latex input.texเพื่อสร้าง dvi แล้วใช้dvisvgm input.dviเพื่อสร้าง SVG ด้วยความโปร่งใส แปลงจาก SVG ในรูปแบบแรสเตอร์เช่น PNG convert -antialias -density 300 -background none input.svg output.pngก็พอง่ายด้วย อย่างไรก็ตามภาพเหล่านี้ดูน่าทึ่งและโปร่งใส ยังคงทำงานเกี่ยวกับปัญหาแบบอักษร ... i.imgur.com/1Xu2Ry5.png
                    gitdagsกำลังจะมา!
                    Gitgเป็นโคลนของ Gitk และ GitX สำหรับ GNOME (ใช้ได้กับ KDE ฯลฯ ) ซึ่งแสดงกราฟสีสวย
มันมีการพัฒนาอย่างแข็งขัน (ณ ปี 2012) มันช่วยให้คุณเรียงลำดับการกระทำ (โหนดกราฟ) ตามลำดับเวลาหรือทอพอโลยีและซ่อนการกระทำที่ไม่นำไปสู่สาขาที่เลือก
มันทำงานได้ดีกับที่เก็บข้อมูลขนาดใหญ่และกราฟการพึ่งพาที่ซับซ้อน
ภาพตัวอย่างหน้าจอแสดงที่เก็บ linux-git และ linux-2.6:
SourceTree เป็นสิ่งที่ดีจริงๆ มันจะพิมพ์ออกมาดูดีและประวัติขนาดกลางและกราฟสาขา: (ต่อไปนี้จะทำในโครงการ Git ทดลองเพียงเพื่อดูบางสาขา) รองรับ Windows 7+ และ Mac OS X 10.6+

ฉันเพิ่งเขียนเครื่องมือหนึ่งที่สามารถสร้างกราฟคอมมิทที่ใช้คอมไพล์ได้ด้วย HTML / Canvas
และจัดทำปลั๊กอิน jQuery ซึ่งทำให้ใช้งานง่าย
[github] https://github.com/tclh123/commits-graph
ตัวอย่าง:

git-forestเป็นสคริปต์ Perl ที่ยอดเยี่ยมที่ฉันใช้มานานกว่าหนึ่งปีและฉันแทบจะไม่ใช้git logคำสั่งโดยตรงอีกเลย
นี่คือบางสิ่งที่ฉันชอบเกี่ยวกับสคริปต์นี้:
--reverseกับเอาต์พุตกราฟซึ่งไม่สามารถทำได้ด้วยgit logคำสั่งปกติgit logภายในเพื่อคว้ารายการการกระทำดังนั้นตัวเลือกทั้งหมดที่คุณส่งไปgit logยังสามารถส่งผ่านไปยังสคริปต์นี้เช่นกันฉันมีนามแฝงที่ใช้git-forestดังนี้:
[alias]
tree = "forest --pretty=format:\"%C(red)%h %C(magenta)(%ar) %C(blue)%an %C(reset)%s\" --style=15 --reverse"
นี่คือลักษณะที่เอาต์พุตดูเหมือนกับเทอร์มินัล:
ฉันเขียนเครื่องมือเว็บสำหรับการแปลงบันทึก git เป็นกราฟ SVG ที่สวย: Bit-Booster - เครื่องมือวาดกราฟคอมมิท Commit
อัปโหลดผลลัพธ์จากgit log --pretty='%h|%p|%d'โดยตรงไปยังเครื่องมือจากนั้นคลิกที่ลิงก์ "ดาวน์โหลด graph.svg"
เครื่องมือนี้เป็นฝั่งไคลเอนต์ดังนั้นจึงไม่มีข้อมูล Git ของคุณแบ่งปันกับเซิร์ฟเวอร์ของฉัน นอกจากนี้คุณยังสามารถบันทึก HTML + JS ภายในเครื่องและเรียกใช้โดยใช้ "file: ///" URL ของ ตรวจสอบแล้วใน Chrome 48 และ Firefox 43 บน Ubuntu 12.04
มันสร้าง HTML ที่สามารถโพสต์ได้โดยตรงในหน้าใด ๆ (รวมถึงเครื่องมือบล็อก blogspot!) ดูที่โพสต์บล็อกบางส่วนได้ที่นี่:
http://bit-booster.blogspot.ca/
นี่คือภาพหน้าจอของไฟล์ HTML ตัวอย่างที่สร้างโดยเครื่องมือ:
http://bit-booster.com/graph.html (เครื่องมือ)
จากสคริปต์ Graphviz ที่ฉันพบในคำตอบของคำถามที่เกี่ยวข้องฉันได้แฮกสคริปต์ rubyที่สร้างมุมมองสรุปของที่เก็บ git มันจะลบประวัติเชิงเส้นทั้งหมดและแสดงการกระทำที่ "น่าสนใจ" เช่นที่มีผู้ปกครองหลายคนเด็กหลายคนหรือชี้ไปที่สาขาหรือแท็ก นี่คือตัวอย่างของกราฟที่สร้างขึ้นสำหรับjquery :

git-big-pictureและBranchMasterเป็นเครื่องมือที่คล้ายกันซึ่งพยายามแสดงเฉพาะโครงสร้างระดับสูงของกราฟโดยแสดงเฉพาะแท็กกิ่งไม้การผสานและอื่น ๆ ที่เกี่ยวข้อง
คำถามนี้มีตัวเลือกเพิ่มเติม
ฉันได้เพิ่มคำสั่งที่กำหนดเองที่สาม: git tree, และgit stree git vtreeฉันจะไปตามลำดับนั้น
[alias]
    tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n         %C(black)[%cr]%C(reset)  %x09%C(black)%an: %s %C(reset)'

ด้วยgit streeและgit vtreeฉันใช้ bash เพื่อช่วยในการจัดรูปแบบ
[alias]
    logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
    stree = !bash -c '"                                                                             \
        while IFS=+ read -r hash time branch message; do                                            \
            timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\");     \
            timelength=$(echo \"16+${#time}-${#timelength}\" | bc);                                 \
            printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"\";          \
        done < <(git logx && echo);"'

[alias]
    logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
    vtree = !bash -c '"                                                                             \
        while IFS=+ read -r hash time branch message; do                                            \
            timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\");     \
            timelength=$(echo \"16+${#time}-${#timelength}\" | bc);                                 \
            printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"$message\";  \
        done < <(git logx && echo);"'

แก้ไข: ใช้งานได้กับ git รุ่น 1.9a เห็นได้ชัดว่าค่าสี 'อัตโนมัติ' เปิดตัวในรุ่นนี้ เป็นการเพิ่มที่ดีเพราะชื่อสาขาจะได้สีที่ต่างกัน สิ่งนี้ทำให้ง่ายต่อการแยกความแตกต่างระหว่างสาขาในพื้นที่และระยะไกล
fatal: bad color value 'auto' for variable '--pretty format':(
                    sed: illegal option -- r
                    ขึ้นอยู่กับสิ่งที่พวกเขาดูเหมือน ฉันใช้gitxซึ่งทำให้ภาพเป็นเช่นนี้:

คุณสามารถเปรียบเทียบgit log --graphกับ gitk กับ octopus merge แบบ 24 ทาง (มีพื้นเพมาจากhttp://clojure-log.n01se.net/date/2008-12-24.html ):

สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับผลลัพธ์ของข้อความโปรดลอง:
git log --graph --date-order -C -M --pretty=format:"<%h> %ad [%an] %Cgreen%d%Creset %s" --all --date=short
คุณสามารถเขียนนามแฝงใน $ HOME / .gitconfig
[alias]
    graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
git hist - แสดงประวัติของสาขาปัจจุบัน
git hist --all - แสดงกราฟของทุกสาขา (รวมถึงรีโมท)
git hist master devel - แสดงความสัมพันธ์ระหว่างสองสาขาขึ้นไป
git hist --branches - แสดงสาขาท้องถิ่นทั้งหมด
เพิ่ม--topo-orderในการจัดเรียงกระทำ topologically แทนตามวันที่ (ค่าเริ่มต้นในนามแฝงนี้)
--decorateดังนั้นมีสีแยกกันสำหรับชื่อสาขาที่แตกต่างกันgit config --global alias.hist "log --graph --date-order --date=short \
--pretty=format:'%C(auto)%h%d %C(reset)%s %C(bold blue)%ce %C(reset)%C(green)%cr (%cd)'"
gitg : โปรแกรมดูพื้นที่เก็บข้อมูลที่ใช้ gtk ซึ่งเป็นของใหม่ แต่น่าสนใจและมีประโยชน์
http://git.gnome.org/browse/gitg
 
ฉันใช้มันในปัจจุบัน
GitXและเป็นสิ่งที่ดีทีเดียว แนะนำ
                    แม้ว่าบางครั้งฉันใช้gitgกลับมาที่ command line เสมอ:
[alias]
    #quick look at all repo
    loggsa = log --color --date-order --graph --oneline --decorate --simplify-by-decoration --all
    #quick look at active branch (or refs pointed)
    loggs  = log --color --date-order --graph --oneline --decorate --simplify-by-decoration
    #extend look at all repo
    logga  = log --color --date-order --graph --oneline --decorate --all
    #extend look at active branch
    logg   = log --color --date-order --graph --oneline --decorate
    #Look with date
    logda  = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\" --all
    logd   = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\"        
    #Look with relative date
    logdra = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\" --all
    logdr = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\"  
    loga   = log --graph --color --decorate --all
    # For repos without subject body commits (vim repo, git-svn clones)
    logt  = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\"
    logta  = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all        
    logtsa = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all --simplify-by-decoration 
อย่างที่คุณเห็นเป็นชื่อแทนการบันทึกการกดแป้นพิมพ์เกือบตาม:
ดูในรุ่นล่าสุดของ git (1.8.5 ขึ้นไป) คุณจะได้รับประโยชน์จาก% C (อัตโนมัติ) ในการตกแต่งตัวยึดตำแหน่ง% d
จากที่นี่สิ่งที่คุณต้องการคือความเข้าใจที่ดีของgitrevisionsในการกรองสิ่งที่คุณต้องการ (สิ่งที่ต้องการ master..develop ที่ - เรียบง่าย - การผสานจะช่วยให้สาขาในระยะยาว)
พลังงานที่อยู่เบื้องหลังบรรทัดคำสั่งคือการกำหนดค่าอย่างรวดเร็วตามความต้องการของคุณ (เข้าใจ repo ไม่ใช่การกำหนดค่าคีย์ล็อกที่ไม่ซ้ำกันดังนั้นการเพิ่ม --numstat หรือ --raw หรือ - ชื่อ - สถานะเป็นสิ่งจำเป็นบางครั้งนี่ git log และนามแฝงนั้นรวดเร็วมีประสิทธิภาพและ (ตามเวลา) กราฟที่สวยที่สุดที่คุณสามารถทำได้ยิ่งไปกว่านั้นด้วยเอาต์พุตที่แสดงโดยค่าเริ่มต้นผ่านเพจเจอร์ (พูดน้อยกว่า) คุณสามารถค้นหาในผลลัพธ์ได้อย่างรวดเร็วไม่เชื่อคุณสามารถแยกผลลัพธ์ได้เสมอ กับโครงการเช่นgitgraph
คำตอบที่ยอดเยี่ยมเล็กน้อยของ Slippคุณสามารถใช้นามแฝงของเขาเพื่อบันทึกเพียงหนึ่งสาขา:
[alias]
lgBranch1 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
lgBranch2 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit
lg = !"git lg1"
โดยออกจาก--allคุณสามารถทำได้
git lgBranch1 <branch name>
หรือแม้กระทั่ง
git lgBranch1 --all
ฉันแนะนำtig https://github.com/jonas/tig 
เครื่องมือบรรทัดคำสั่งที่ดีกว่ามากสำหรับ git
คุณสามารถใช้ homebrew เพื่อติดตั้ง tig บน macOS:
$ brew install tig
$ tig
ฉันมีgit logนามแฝงนี้~/.gitconfigเพื่อดูประวัติกราฟ:
[alias]
l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
ด้วยสิ่งนี้ในสถานที่git lจะส่งออกสิ่งที่ชอบ:
ใน Git 2.12 + คุณสามารถปรับแต่งสีเส้นของกราฟโดยใช้log.graphColorsตัวเลือกการกำหนดค่า
สำหรับรูปแบบล็อกก็คล้ายกับ--onelineมีการเพิ่มของชื่อผู้เขียน (เคารพ.mailmap) และวันที่ผู้เขียนญาติ โปรดทราบว่า%C(auto)ไวยากรณ์ซึ่งบอก Git ที่จะใช้สีเริ่มต้นสำหรับการกระทำกัญชา ฯลฯ ได้รับการสนับสนุนใน Git> = 1.8.3
git log --graph --oneline  เพียงเพื่อให้แน่ใจว่า oneliner จะไม่หลงทาง
                    GitGraph
สร้าง PNG หรือ SVG เพื่อแสดงประวัติการกระทำของที่เก็บ Git ของคุณ
git -c core.pager='less -SRF' log --oneline --graph --decorate
นี่คือรูปแบบเทอร์มินัลของฉันคล้ายกับคำตอบมากมายที่นี่ ฉันต้องการปรับค่าสถานะที่ส่งผ่านlessเพื่อป้องกันการตัดคำ
ฉันตั้งค่านี้เป็นนามแฝงสำหรับการเข้าถึงที่รวดเร็วเนื่องจากคำสั่งค่อนข้างยุ่งยาก
ลองditaa มันสามารถแปลงแผนภาพ ASCII ใด ๆ ให้เป็นภาพ แม้ว่าจะไม่ได้ออกแบบโดยคำนึงถึงสาขาของ Git แต่ฉันก็ประทับใจกับผลลัพธ์
ที่มา (ไฟล์ txt):
        +--------+
        | hotfix |
        +---+----+
            |
--*<---*<---*
       ^ 
       |
       \--*<---*
               |
           +---+----+
           | master |
           +--------+
คำสั่ง:
java -jar ditaa0_9.jar ascii-graph.txt
ผลลัพธ์:
นอกจากนี้ยังสนับสนุนสีพื้นหลังเส้นประรูปร่างที่แตกต่างและอื่น ๆ ดูตัวอย่าง
หากพื้นที่เก็บข้อมูลของคุณตั้งอยู่บน Gitlab คุณสามารถใช้การแสดงกราฟของมันตามที่แสดงเป็น SVG ในเบราว์เซอร์ของคุณ
ไปที่มุมมองกราฟของที่เก็บของคุณเช่นhttps://gitlab.com/gitlab-org/gitter/webapp/network/develop
เลื่อนกราฟลงไปที่ด้านล่าง (โหลดแบบขี้เกียจคอมมิท!)
ใช้เครื่องมือตรวจสอบของเบราว์เซอร์ของคุณเพื่อคัดลอกองค์ประกอบ SVG ไปยังไฟล์ใหม่
เปิดในโหมดแสดงภาพที่คุณเลือกเช่น Inkscape
ฉันไม่รู้เกี่ยวกับเครื่องมือโดยตรง แต่บางทีคุณสามารถแฮ็คสคริปต์เพื่อส่งออกข้อมูลในรูปแบบจุดและแสดงด้วยกราฟวิส
ioคำสั่งเหล่านั้นให้เป็นคำสั่ง perl `git log [... ]` ที่ใช้งานได้ง่ายสำหรับฉัน
                    brew install perl dotและจากนั้นcpan common::sense IO::allจะได้รับการอ้างอิง git-graphviz | dot -Tpng -o repo.pngจากนั้นเพียงแค่ท่อส่งออกไปยังคำสั่งที่เหมาะสมเช่น อย่างไรก็ตามผลลัพธ์ไม่ได้แตกต่างจากgit-big-pictureมาก
                    มี Git ขี้ขลาดกระทำกราฟเป็นหนึ่งในการสาธิตของกราฟิลส์ห้องสมุดกราฟิกเว็บ
การสาธิตนั้นเป็นแบบสแตติก แต่ควรง่ายพอที่จะใช้รหัสและสลับข้อมูลสแตติกของพวกเขาเป็นชุดข้อมูลสด - ฉันคิดว่ามันเป็นเพียง Git ที่ส่งข้อมูลในรูปแบบ JSON
ตัวอย่างอยู่ที่นี่: http://dmitrybaranovskiy.github.io/raphael/github/impact.html
เอาท์พุทกราฟ git tablelike ที่ดีและสะอาดสำหรับเชลล์
พร้อมกับแฮชตามปกตินอกเหนือจากแผนภูมิกราฟ
หรือในคอลัมน์เพิ่มเติม
แก้ไข : คุณต้องการเริ่มต้นทันทีโดยไม่ต้องอ่านคำอธิบาย? ใช้นามแฝง git, สคริปต์หรือตัวอย่างรหัสฟังก์ชั่นจากส่วนEDIT 5ด้านล่าง
ในคำตอบทั้งหมดสำหรับคำถามนี้ไม่มีผู้ใดแสดงให้เห็นถึงแท็บเล็ตที่ดูสะอาดเหมือนเดิม ที่ใกล้ที่สุดคือคำตอบนี้จากพระประวัติที่ฉันเริ่มต้น
ประเด็นหลักในแนวทางของฉันคือการนับเฉพาะอักขระต้นไม้ที่แสดงต่อผู้ใช้ จากนั้นเติมความยาวส่วนบุคคลด้วยช่องว่าง
นอกเหนือจากคอมไพล์คุณต้องการเครื่องมือเหล่านี้
ส่วนใหญ่บนกระดานกับการกระจาย linux ใด ๆ
ข้อมูลโค้ดคือ
while IFS=+ read -r graph hash time branch message;do
  # count needed amount of whitespaces and create them
  whitespaces=$((9-$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)))
  whitespaces=$(seq -s' ' $whitespaces|tr -d '[:digit:]')
  # show hashes besides the tree ...
  #graph_all="$graph_all$graph$(printf '%7s' "$hash")$whitespaces \n"
  # ... or in an own column
  graph_all="$graph_all$graph$whitespaces\n"
  hash_all="$hash_all$(printf '%7s' "$hash")  \n"
  # format all other columns
  time_all="$time_all$(printf '%12s' "$time") \n"
  branch_all="$branch_all$(printf '%15s' "$branch")\n"
  message_all="$message_all$message\n"
done < <(git log --all --graph --decorate=short --color --pretty=format:'+%C(bold 214)%<(7,trunc)%h%C(reset)+%C(dim white)%>(12,trunc)%cr%C(reset)+%C(214)%>(15,trunc)%d%C(reset)+%C(white)%s%C(reset)' && echo);
# paste the columns together and show the tablelike output
paste -d' ' <(echo -e "$time_all") <(echo -e "$branch_all") <(echo -e "$graph_all") <(echo -e "$hash_all") <(echo -e "$message_all")
ในการคำนวณช่องว่างที่จำเป็นที่เราใช้
  sed -nl500 'l' <<< "$graph"
เพื่อรับอักขระทั้งหมด (จนถึง 500 ต่อบรรทัด) กว่าเลือกเฉพาะอักขระต้นไม้: * | / \ _ และช่องว่างด้วย
  grep -Eo '\\\\|\||\/|\ |\*|_'
ในที่สุดก็นับพวกมันและลบล้างผลลัพธ์จากค่าความยาวที่เราเลือกซึ่งก็คือ 9 ในตัวอย่าง
ในการผลิตจำนวนช่องว่างที่คำนวณได้ที่เราใช้
  seq -s' ' $whitespaces
และตัดทอนหมายเลขตำแหน่งด้วย
  tr -d '[:digit:]'
กว่าเพิ่มลงในส่วนท้ายของเส้นกราฟของเรา แค่นั้นแหละ!
Git มีตัวเลือกที่ดีในการจัดรูปแบบความยาวของตัวระบุผลลัพธ์ด้วยไวยากรณ์แล้ว'%><(amount_of_characters,truncate_option)'ซึ่งเพิ่ม whitespaces จากด้านซ้าย '>' หรือด้านขวา '<' และสามารถตัดอักขระจากจุดเริ่มต้น 'ltrunc', กึ่งกลาง 'mtrunc' หรือสิ้นสุด 'TRUNC'
เป็นสิ่งสำคัญที่ด้านบนของ printf cmd ใช้ค่าความยาวเท่ากันสำหรับคอลัมน์ git ที่เกี่ยวข้อง
ขอให้สนุกกับการออกแบบสไตล์แท็บเล็ตที่ดูสะอาดตาตามที่คุณต้องการ
เสริม:
ในการรับค่าความยาวที่ถูกต้องคุณสามารถใช้ตัวอย่างต่อไปนี้
while read -r graph;do
    chars=$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)
    [[ $chars -gt ${max_chars:-0} ]] && max_chars=$chars
done < <(git log --all --graph --pretty=format:' ')
และใช้ $ max_chars เป็นค่าความยาวที่ถูกต้องด้านบน
แก้ไข 1 : เพิ่งสังเกตเห็นว่าการขีดเส้นใต้กุศลยังใช้ในต้นไม้ git และแก้ไขโค้ดด้านบน หากมีตัวละครอื่นหายไปโปรดแสดงความคิดเห็น
แก้ไข 2 : หากคุณต้องการกำจัดวงเล็บรอบรายการสาขาและแท็กเพียงแค่ใช้ "% D" แทน "% d" ในคำสั่ง git เช่นใน EDIT 3
แก้ไข 3 : ตัวเลือกสี "อัตโนมัติ" อาจเป็นตัวเลือกที่คุณชอบมากที่สุดสำหรับรายการสาขาและแท็กใช่หรือไม่
เปลี่ยนส่วนนี้ของคำสั่ง git (color 214 )
%C(214)%>(15,trunc)%D%C(reset)
เป็นอัตโนมัติ
%C(auto)%>(15,trunc)%D%C(reset)
แก้ไข 4 : หรือคุณชอบสีผสมของคุณเองสำหรับส่วนนั้นออกแฟนซีกับหัวกระพริบ?
เพื่อให้สามารถจัดสไตล์ส่วนหัวชื่อสาขาและแท็กอันดับแรกเราต้องใช้ตัวเลือกสี "อัตโนมัติ" ในคำสั่ง git ของเราเช่นใน EDIT 3
จากนั้นเราสามารถแทนที่ค่าสีรู้ด้วยของเราเองโดยเพิ่ม 3 บรรทัดนี้
 # branch name styling
 branch=${branch//1;32m/38;5;214m}
 # head styling
 branch=${branch//1;36m/3;5;1;38;5;196m}
 # tag styling
 branch=${branch//1;33m/1;38;5;222m}
ก่อนบรรทัด
 branch_all="$branch_all$(printf '%15s' "$branch")\n"
ในข้อมูลโค้ดของเรา ค่าการแทนที่จะสร้างสีด้านบน
ตัวอย่างเช่นค่าทดแทนสำหรับหัวคือ
3;5;1;38;5;196
ที่ไหน 3; ย่อมาจากตัวเอียง 5; สำหรับการกะพริบและ 1; 38; 5; 196 สำหรับสี สำหรับข่าวสารเพิ่มเติมเริ่มที่นี่ หมายเหตุ: พฤติกรรมนี้ขึ้นอยู่กับเทอร์มินัลที่คุณชื่นชอบและอาจไม่สามารถใช้งานได้
แต่คุณสามารถเลือกค่าสีที่คุณต้องการ
ภาพรวมของค่าสี git และ ANSI ที่เทียบเท่า
คุณพบว่ารายการที่มีตัวเลือกสี / รูปแบบคอมไพล์ที่นี่
หากคุณต้องการเอาท์พุทบนคอนโซลของคุณสำหรับสีที่ถูกต้อง (ภาพด้านบนถูกลดขนาดลงโดย stackoverflow) คุณสามารถสร้างเอาต์พุตด้วย
for ((i=0;i<=255;i++));do
  while IFS='+' read -r tree hash;do 
    echo -e "$(printf '%-10s' "(bold $i)") $hash  $(sed -nl500 'l' <<< "$hash"|grep -Eom 1 '[0-9;]*[0-9]m'|tr -d 'm')"
  done < <(git log --all --graph --decorate=short --color --pretty=format:'+%C(bold '$i')%h%C(reset)'|head -n 1)
done
ในพา ธ โครงการ git ของคุณซึ่งใช้คอมมิทแรกจากไฟล์บันทึก git ของคุณ
แก้ไข 5 : ในฐานะสมาชิก "Andras Deak" กล่าวถึงมีบางวิธีวิธีการใช้รหัสนี้:
1) เป็นนามแฝง :
นามแฝงไม่ยอมรับพารามิเตอร์ แต่ฟังก์ชั่นสามารถดังนั้นเพียงกำหนดใน. bashrc ของคุณ
   function git_tably () {
     unset branch_all graph_all hash_all message_all time_all max_chars
     ### add here the same code as under "2) as a shell-script" ###
   }
และเรียกใช้ฟังก์ชัน git_tably (มาจาก tablelike) โดยตรงภายใต้พา ธ โครงการ git ของคุณหรือจากที่ใดก็ตามที่คุณต้องการด้วยพา ธ โครงการ git ของคุณเป็นพารามิเตอร์แรก
2) เป็นเปลือกสคริปต์ :
ฉันใช้มันพร้อมกับตัวเลือกในการส่งไดเรกทอรีโครงการ git เป็นพารามิเตอร์แรกให้หรือถ้าว่างให้ใช้ไดเรกทอรีการทำงานเช่นพฤติกรรมปกติ มันคือทั้งหมดที่เรามี
# edit your color/style preferences here or use empty values for git auto style
tag_style="1;38;5;222"
head_style="1;3;5;1;38;5;196"
branch_style="38;5;214"
# determine the max character length of your git tree
while IFS=+ read -r graph;do
  chars_count=$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)
  [[ $chars_count -gt ${max_chars:-0} ]] && max_chars=$chars_count
done < <(cd "${1:-"$PWD"}" && git log --all --graph --pretty=format:' ')
# create the columns for your prefered tablelike git graph output
while IFS=+ read -r graph hash time branch message;do
  # count needed amount of whitespaces and create them
  whitespaces=$(($max_chars-$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)))
  whitespaces=$(seq -s' ' $whitespaces|tr -d '[:digit:]')
  # show hashes besides the tree ...
  #graph_all="$graph_all$graph$(printf '%7s' "$hash")$whitespaces \n"
  # ... or in an own column
  graph_all="$graph_all$graph$whitespaces\n"
  hash_all="$hash_all$(printf '%7s' "$hash")  \n"
  # format all other columns
  time_all="$time_all$(printf '%12s' "$time") \n"
  branch=${branch//1;32m/${branch_style:-1;32}m}
  branch=${branch//1;36m/${head_style:-1;36}m}
  branch=${branch//1;33m/${tag_style:-1;33}m}
  branch_all="$branch_all$(printf '%15s' "$branch")\n"
  message_all="$message_all$message\n"
done < <(cd "${1:-"$PWD"}" && git log --all --graph --decorate=short --color --pretty=format:'+%C(bold 214)%<(7,trunc)%h%C(reset)+%C(dim white)%>(12,trunc)%cr%C(reset)+%C(auto)%>(15,trunc)%D%C(reset)+%C(white)%s%C(reset)' && echo);
# paste the columns together and show the tablelike output
paste -d' ' <(echo -e "$time_all") <(echo -e "$branch_all") <(echo -e "$graph_all") <(echo -e "$hash_all") <(echo -e "$message_all")
3) เป็นนามแฝงคอมไพล์ :
บางทีวิธีที่สะดวกสบายที่สุดคือการเพิ่มชื่อแทน git ใน. gitconfig ของคุณ
[color "decorate"]
    HEAD = bold blink italic 196
    branch = 214
    tag = bold 222
[alias]
    count-log = log --all --graph --pretty=format:' '
    tably-log = log --all --graph --decorate=short --color --pretty=format:'+%C(bold 214)%<(7,trunc)%h%C(reset)+%C(dim white)%>(12,trunc)%cr%C(reset)+%C(auto)%>(15,trunc)%D%C(reset)+%C(white)%s%C(reset)'
    tably     = !bash -c '"                                                                                                    \
                  while IFS=+ read -r graph;do                                                                                 \
                    chars_count=$(sed -nl1000 \"l\" <<< \"$graph\" | grep -Eo \"\\\\\\\\\\\\\\\\|\\||\\/|\\ |\\*|_\" | wc -l); \
                    [[ $chars_count -gt ${max_chars:-0} ]] && max_chars=$chars_count;                                          \
                  done < <(git count-log && echo);                                                                             \
                  while IFS=+ read -r graph hash time branch message;do                                                        \
                    chars=$(sed -nl1000 \"l\" <<< \"$graph\" | grep -Eo \"\\\\\\\\\\\\\\\\|\\||\\/|\\ |\\*|_\" | wc -l);       \
                    whitespaces=$(($max_chars-$chars));                                                                        \
                    whitespaces=$(seq -s\" \" $whitespaces|tr -d \"[:digit:]\");                                               \
                    graph_all=\"$graph_all$graph$whitespaces\n\";                                                              \
                    hash_all=\"$hash_all$(printf \"%7s\" \"$hash\")  \n\";                                                     \
                    time_all=\"$time_all$(printf \"%12s\" \"$time\") \n\";                                                     \
                    branch_all=\"$branch_all$(printf \"%15s\" \"$branch\")\n\";                                                \
                    message_all=\"$message_all$message\n\";                                                                    \
                  done < <(git tably-log && echo);                                                                             \
                  paste -d\" \" <(echo -e \"$time_all\") <(echo -e \"$branch_all\") <(echo -e \"$graph_all\")                  \
                                <(echo -e \"$hash_all\") <(echo -e \"$message_all\");                                          \
                '"
มากกว่าแค่โทรgit tablyตามเส้นทางของโครงการ
Git มีประสิทธิภาพเพื่อให้คุณสามารถเปลี่ยนหัวแท็ก ... โดยตรงตามที่แสดงไว้ข้างต้นและนำมาจากที่นี่
อีกตัวเลือกแฟนซีคือการเลือกสีต้นไม้ที่คุณชอบมากที่สุดด้วย
[log]
    graphColors = bold 160, blink 231 bold 239, bold 166, bold black 214, bold green, bold 24, cyan
ที่ให้คุณดูบ้าคลั่ง แต่จะแสดงผลบันทึก git tablelike เสมอ
กะพริบมากเกินไป! เพียงเพื่อแสดงให้เห็นถึงสิ่งที่เป็นไปได้ สีที่ระบุน้อยเกินไปนำไปสู่การทำซ้ำสี
การอ้างอิง. gitconfig ที่สมบูรณ์เพียงแค่คลิกเดียว
อีกครั้ง: ขอให้สนุกกับการออกแบบแท็บเล็ตที่ดูสะอาดตาตามที่คุณต้องการ
นามแฝงบางตัวใน ~ / .oh-my-zsh / plugins / git / git.plugin.zsh
gke='\gitk --all $(git log -g --pretty=%h)'
glg='git log --stat'
glgg='git log --graph'
glgga='git log --graph --decorate --all'
glgm='git log --graph --max-count=10'
glgp='git log --stat -p'
glo='git log --oneline --decorate'
glog='git log --oneline --decorate --graph'
gloga='git log --oneline --decorate --graph --all'
glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
สำหรับผู้ใช้ OSX ฉันได้นำตัวอย่าง @gospes และปรับเปลี่ยนเล็กน้อยสำหรับ gsed ( gnu-sedติดตั้งผ่าน homebrew) และปรับสี (เพื่อทำงานกับพื้นหลังสีดำไม่แน่ใจว่าตัวอย่างดั้งเดิมอาจแสดงวิธีการในแบบ ตัวอย่างเนื่องจากมันระบุข้อความสีดำใน terminal ที่มีพื้นหลังสีดำ)
[alias]
    # tree, vtree, stree support
    logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(bold black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(bold black): %s%C(reset)'
    tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n         %C(bold black)[%cr]%C(reset)  %x09%C(bold black)%an: %s %C(reset)'
    stree = !bash -c '" \
    while IFS=+ read -r hash time branch message; do \
        timelength=$(echo \"$time\" | gsed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\"); \
        timelength=$(echo \"16+${#time}-${#timelength}\" | bc); \
        printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"\"; \
    done < <(git logx && echo);"' | less -r
    vtree = !bash -c '" \
    while IFS=+ read -r hash time branch message; do \
      timelength=$(echo \"$time\" | gsed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\"); \
      timelength=$(echo \"16+${#time}-${#timelength}\" | bc); \
      printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"$message\"; \
    done < <(git logx && echo);"' | less -r
กุญแจสำคัญสำหรับ OSX คือการติดตั้ง gnu sed ก่อน (ซึ่งมีตัวเลือก -r) ทำได้ง่ายที่สุดกับ homebrew ซึ่งจะไม่เขียนทับ sed ที่ติดตั้งระบบ แต่จะติดตั้ง gnu sed แทน "gsed" แทน หวังว่านี่จะช่วยให้ @ SlippD.Thompson ที่แสดงความคิดเห็นข้างต้นเกี่ยวกับ OSX ไม่ทำงาน