git生成文件目錄樹及日志打印


@

如何用git生成一個文件目錄樹

因為Git-Bash中不支持tree命令,所有需要給Window平台下Git-Bash添加tree命令

參考 https://www.jianshu.com/p/32ba82d84680

下載 tree 命令的二進制包,安裝 tree 命令工具;

  1. 打開進入 Tree for Windows 頁面,選擇下載 Binaries zip 文件;
  2. 解壓壓縮包,找到壓縮包內的 bin 目錄,將 bin 目錄下的 tree.exe 復制;
  3. 找到 C:\\Program Files\Git\usr\bin 目錄,將 tree.exe 粘貼到該目錄下,安裝即完成;

測試 tree 命令

  1. 進入 Git-Bash,輸入 tree -L 1 命令,如果安裝成功,命令可以正常執行。tree展示
  2. tree -L 5 -I "node_modules|dist|dist.zip" >tree.txt 將目錄結構導出

常用指令

tree -d 只顯示文件夾;
tree -L n 顯示項目的層級。n表示層級數。比如想要顯示項目三層結構,可以用tree -l 3;
tree -I pattern 用於過濾不想要顯示的文件或者文件夾。比如你想要過濾項目中的node_modules文件夾,可以使用tree -I "node_modules",過濾多個用 | 隔開 ,比如 tree -I "node_modules|dist"
tree > tree.md 將項目結構輸出到tree.md這個文件。

更多命令參考 https://wangchujiang.com/linux-command/c/tree.html

目錄結構顯示

├── README.md 項目描述
├── app  業務側代碼
│   ├── controller 與路由關聯的api方法
│   └── modal 數據模型
├── app.js 入口文件
├── bin nodemon
│   ├── run  nodemon 的入口文件
│   └── www
├── config 配置文件
│   ├── dbConfig.js 數據庫配置
│   ├── logConfig.js 日志配置 
│   └── serverConfig.js 服務配置
├── logs  日志目錄
│   ├── error 錯誤日志
│   └── response 普通響應日志 (還可以繼續拆分,系統日志,業務日志)
├── middleware  中間件
│   └── loggers.js  日志中間件
├── public
│   └── stylesheets 公用文件
├── routes  路由
│   ├── allRoute.js 總路由配置
│   ├── files.js 各個模塊路由配置
│   ├── index.js
│   └── users.js
├── uploads 上傳文件夾
│   └── 2017-8-29
├── utils 公用方法
│   ├── logUtil.js 
│   └── mkdir.js
├── views 頁面層
│   ├── error.jade
│   ├── index.jade
│   └── layout.jade
└── package.json


tree 目錄生成命令

tree -L 3 -I "node_modules"

Git如何打印出指定格式log

輸出指定格式的日志信息

git log --graph --after="1 week ago" --oneline --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset - %Cgreen(%ad) %C(yellow)%d%Creset %s ' --abbrev-commit
在這里插入圖片描述
--graph 圖像化顯示日志操作
--after="1 week ago" 顯示一周前的日志信息
--after="2018-12-3" --before="2018-12-7" 獲取該時間段內的日志信息
--oneline 日志信息顯示在一行
--author="tom" 篩選出作者提交的日志
--date=format:'%Y-%m-%d %H:%M:%S' 設置日期顯示格式
--pretty=format: 設置日志顯示格式
%h 提交對象的簡短哈希字串
%ad 作者修訂日期(可以用-date= 選項定制格式)
%ar 作者修訂日期,按多久以前的方式顯示
%s 提交說明
%Cred 切換到紅色
%Cgreen 切換到綠色
%Cblue 切換到藍色
%Creset 重設顏色
-- >f:/work/worklog/log.log 將文件導出到指定文件

更多命令參考 https://ruby-china.org/topics/939

將日志導出到指定目錄

git log --graph --after="1 week ago" --oneline --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset - %Cgreen(%ad) %C(yellow)%d%Creset %s ' --abbrev-commit -- >f:/work/worklog/log.log

給命令設置別名

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
通過 git lg 進行調用

Git打印退出命令

q 退出打印

參考 https://blog.csdn.net/liangxiaozhang/article/details/7903861


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM