原文地址:https://wyiyi.github.io/amber/2024/04/01/git-commit-tree/
description: "安利一個小工具:Git 倉庫 Commit 文件樹查看器。"
date: 2024.03.31 10:34
categories:
- Git
tags: [Git, Shell]
keywords: git, bash, tree, commit, browser, repo, terminal
痛點
在Git
項目中夸楣,代碼的頻繁迭代會使得追蹤項目文件結構變化的過程異常艱難宾抓,尤其是歷史 commit
中存在、當前最新版本中已經(jīng)不存在的文件/文件夾豫喧。
為了解決這個問題洞慎,Git Commit Tree Browser
提供了一個高效的解決方案。
簡介
Git Commit Tree Browser 是基于Bash
的腳本工具嘿棘,通過為每個 commit
生成文件目錄樹,并配備交互式的瀏覽界面旭绒,可視化展示 Git
倉庫各個 commit
狀態(tài)下的文件樹結構鸟妙。
效果
功能特點
- 為指定
Git
倉庫中每個commit
生成文件目錄樹文件 - 提供終端交互界面,通過左右箭頭鍵切換查看不同
commit
的文件目錄樹狀態(tài)挥吵;按回車后激活跳轉到指定commit
模式重父,輸入commit
ID(加文件擴展名.txt
)完成跳轉
使用方法
前置條件
- 工具使用 Bash 腳本實現(xiàn),需可執(zhí)行 Bash 腳本的終端環(huán)境(
Windows
操作系統(tǒng)可在Git Bash
中使用) - 工具依賴
tree
命令生成文件樹結構忽匈,如終端中無法使用需提前安裝(Windows
用戶可以在Git Bash
中安裝 Tree for Windows)
執(zhí)行 prepare.sh 腳本
執(zhí)行 prepare.sh
腳本房午,傳入 Git
倉庫的路徑作為參數(shù):
$ git clone https://github.com/AlphaHinex/git-commit-tree-browser
$ cd git-commit-tree-browser
$ ./prepare.sh /path/to/your/git/repo
腳本將遍歷指定 Git 倉庫的所有 commit
,并為每個 commit
在當前路徑生成文件目錄樹文本文件 <commit_id>.txt
丹允。
當前生成目錄樹使用的命令是 tree -N -d -L 3郭厌,即只顯示文件夾,最多顯示三級路徑雕蔽≌勰可根據(jù)實際需要進行調整。
執(zhí)行 browser.sh 腳本
執(zhí)行 browser.sh
腳本批狐,開始按 commit
從老到新的順序進行文件目錄樹瀏覽:
$ ./browser.sh
終端中將顯示第一個commit
的文件目錄樹扇售,如:
File: 20df792.txt
.
|-- bronze
| |-- gradle
| | `-- wrapper
| `-- src
| |-- main
| `-- test
`-- git-commit-tree-browser
7 directories
20df792
Press left/right arrow to navigate, or Enter to jump to a file:
可以使用以下方式導航:
- 使用左右箭頭鍵在不同的
commit
之間切換 - 按
Enter
鍵,然后輸入<commit_id>.txt
文件名嚣艇,直接跳轉到特定的commit
小工具會繼續(xù)豐富功能承冰,請期待~~~