Skip to content

波林部落客

PolinWEI Blog

  • PHP
  • WordPress
  • Laravel
  • VueJS
  • D365 Business Central
  • 網路技術
  • Toggle search form
  • image 1
    Laravel 在 api 中透過 put 方法傳入參數時進行型別轉換 Laravel
  • image 8
    VueJS 父子組件與資料傳遞 VueJS
  • image 7
    VueJS 對於 v-for 正確的寫法 VueJS
  • 受保護的內容: 鼎新ERP成品批號追蹤追溯(含配方組合單)SQL 網路技術
  • image 19
    在 Windows 安裝 Nginx + PHP + MariaDB 環境 Web Server
  • 工作必備—Windows 11 虛擬桌面與雙螢幕快捷鍵 網路技術
  • SQL Server 年度區間查詢範例 網路技術
  • image 3
    D365 Business Central (BC) AL 客製開發物件 ID 引用指南 D365 Business Central

git commit 的前置腳本 post-commit

Posted on 2025-12-272025-12-27 By polinwei 在〈git commit 的前置腳本 post-commit〉中尚無留言

在 post-commit 腳本中,可以使用 Shell 腳本的條件語句(if [ -z ... ])來檢查環境變數是否有值。

以下是針對 git commit 時,更新版本資訊的 .git/hooks/post-commit 腳本:

Table of Contents

Toggle
  • 撰寫 post-commit 腳本
  • 如何在終端機使用
    • 一般提交 (不帶環境參數)
    • 測試環境提交
    • 正式環境提交

撰寫 post-commit 腳本

這個腳本會檢查 GIT_APP_ENV 是否存在。如果為空,就執行基礎指令;如果有值,則帶上 --env 參數。

Bash
#!/bin/sh

# 取得環境變數 (由 git commit 指令前置傳入)
TARGET_ENV=$GIT_APP_ENV

if [ -z "$TARGET_ENV" ]; then
    # 情況 A: 沒傳入環境參數
    echo "未偵測到環境參數,執行基礎版本更新..."
    php artisan version:update
else
    # 情況 B: 有傳入環境參數 (例如 test)
    echo "偵測到環境參數: $TARGET_ENV,執行特定環境更新..."
    php artisan version:update --env="$TARGET_ENV"
fi

如何在終端機使用

現在可以根據需求靈活選擇 Commit 方式:

一般提交 (不帶環境參數)

Bash
git commit -m "feat: 修正備份邏輯"
# 這會觸發:php artisan version:update

測試環境提交

Bash
GIT_APP_ENV=test git commit -m "feat: 測試新功能"
# 這會觸發:php artisan version:update --env=test

正式環境提交

Bash
GIT_APP_ENV=production git commit -m "fix: 緊急修復"
# 這會觸發:php artisan version:update --env=production
網路技術 Tags:git

文章導覽

Previous Post: laravel 12 備份及還原資料庫
Next Post: 在 Business Central 的 Report(AL) 中查詢相關連資訊

Related Posts

  • 受保護的內容: 鼎新ERP批號溯源(Lot Tracing)逆向查詢SQL 網路技術
  • mmc add ad schema 768x531 1
    Active Directory 操作主機角色移轉與拿取 網路技術
  • image 1
    powershell 語法的 login script 用於微軟 Active Directory (AD) 網路技術
  • image 20
    設定 FortiGate 目前封鎖的單一網站(將加入白名單)可以存取 網路技術
  • SQL Server 年度區間查詢範例 網路技術
  • SQL Server 日期查詢範例 網路技術

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


AL Language apache blade database debug DNS Eloquent extension fortigate git linux middleware nginx Office 365 permission Power BI powershell queue redis Springboot SQL Server timezone trait Visual Studio Code vue3 windows zabbix 佈景主題 教學

  • image 21
    Laravel 中的同步(Sync)、附加(Attach)和分離(Detach):使用 Eloquent 管理關係 Laravel
  • image 14
    客製程式在 Business Central 的權限設定與賦予權限 D365 Business Central
  • 如何防止 WordPress 管理列與 Twitter Bootstrap 導覽列重疊 WordPress
  • 在 Business Central 的 Report(AL) 中查詢相關連資訊 D365 Business Central
  • SQL Server 年度區間查詢範例 網路技術
  • image 8
    將 Business Central 正式區(Production)複製(Copy)到測試環境(Sandbox) D365 Business Central
  • image 12
    Laravel 將「點閱記錄」改成非同步 queue 寫入資料庫 Laravel
  • SQL Server 中印出游標(Cursor)裡值的基本寫法 網路技術

Copyright © 2026 波林部落客.

Powered by PressBook News WordPress theme

Advertisement