星期五, 20 6 月, 2025
No Result
View All Result
育心文具行

育心文具行

  • 首頁
  • 心得x體驗
  • 筆記x備忘
  • 閒談x雜記
  • 我的工具箱
  • 關於我
育心文具行
  • 首頁
  • 心得x體驗
  • 筆記x備忘
  • 閒談x雜記
  • 我的工具箱
  • 關於我
No Result
View All Result
育心文具行
Home 筆記x備忘

vue3 學習筆記 EP3

處理編輯檔以及編譯後檔案的部屬

2023-10-09
in 筆記x備忘
Reading Time:1 mins read
A A
0

直譯語言和編譯語言是程式語言的一種分類,自己在有 server-side 的程式中寫 PHP 寫久了,都快忘記編譯語言會有編輯檔案以及編譯後的檔案。 這時會開始苦惱幾個需求:

  1. 在 server 上只 pull 下編譯後檔案即可
  2. 編輯檔還是需要版控
  3. server 上儘量不要搞太多東西,要不以後架設會很麻煩
  4. 儘量自動化

版控使用 git 來實現,因為部屬到 server 是 master branch,所以打算開一個 dev branch 來處理編輯,然後測試沒問題以後再 marge 到 master branch ,然後 npm run build 把產生的 dist 的資料夾(編譯後的檔案) push 上去。

參考:

gist.github.com
HowTo have specific .gitignore for each git branch
HowTo have specific .gitignore for each git branch - gitignore_per_git_branch.md

可以透過 git 之中的 hook 達到目的。

他的原理是透過 git hook 在 checkout 的時候,取得對應不同 branch 的 .gitignore.{branch name} 檔案,讀取裡面的設定實現 git ignore 的功能,以達到不同 branch 能夠指定不同需要 ignore 檔案的目的。

主要的作法是在 .git/hooks 之中建立一個 post-checkout 檔案(該檔案名稱對應 hook 行為):

#!/bin/sh

old_ref=$1
new_ref=$2
branch_switched=$3

if [[ $branch_switched != '1' ]]
then
    exit 0
fi
echo "---- POST CHECKOUT ----"
current_branch=$(git rev-parse --abbrev-ref HEAD)
hook_dir=$(dirname $0)
root_dir="$(pwd -P)"
info_dir="$root_dir/.git/info"

exclude_target='.gitignore'
if [[ -f "$root_dir/$exclude_target.$current_branch" ]]
then
	echo "Prepare to use .gitignore.$current_branch as exclude file"
    exclude_target=.gitignore.$current_branch
fi
cd "$info_dir"
rm exclude
#ln -s $exclude_target exclude
echo "Copy .gitignore.$current_branch file in place of exclude"
cp "$root_dir/$exclude_target" exclude
echo "--- POST CHECKOUT END ---"

然後執行 git init ,重新啟用 git hooks。

之後實作 .gitignore 時,檔案名稱依照分支加上後綴即可。例如是 dev 分支下,添加 .gitignore.dev 檔案即可生效;在 master 中,添加 .gitignore.master 就行啦。

附上設定截圖更清楚:

 

同場加映:

git-scm.com
Git - githooks Documentation
zh.wikipedia.org
CI/CD - 維基百科,自由的百科全書
Tags: devdistgitgit hookgitignorehookvue
Share22Tweet14
Previous Post

vue3 學習筆記 EP2

Next Post

Linode 伺服器調整規格與調整硬碟空間配置

Related Posts

筆記x備忘

將現成的 git repo 添加現成的專案資料夾

這是一個 git 小技巧,其實滿常用的,...

2025-05-09
100
筆記x備忘

Git Push 太久解決方法

Git 有時 push 太久一直無法結束...

2025-02-04
100
心得x體驗

vue3 學習筆記 EP4

axios 套件介紹,請參考這裡。 這是...

2022-10-16
100
Load More
Next Post

Linode 伺服器調整規格與調整硬碟空間配置

《QBQ!問題背後的問題》  

vue3 學習筆記 EP4

全站搜尋

No Result
View All Result

關於我

育心文具行

Jerry Lin

程式設計師

育心文具行是一家文具店,老闆的小兒子是一個設計師,職業是設計程式,興趣是設計人,倒是還沒有實作的機會。
--
所有的相遇都不是巧合。
在廣告公司待了三年有兩年多在做內容產品,離職後繼續在內容產業走了四年多,最後選則離開台灣的公司體制在家 SOHO ,碰上了 2020 年疫情才知道原來自己這是走在時代的潮流尖端。 感謝許多老闆和貴人相助,至今目前尚能存活,在台北街頭努力著。

近期文章

  • 於 MacOS 中,整合自然語言,自動化添加行事曆事件
  • 使用 deepwiki-open 針對程式碼產生 WIKI
  • 使用 Tailwind CLI 快速建立靜態 CSS 檔的基本步驟
  • Visual Studio Code 的 PHP CS Fixer 設定
  • MacOS 添加本地伺服器的 DNS

分類

  • 心得x體驗 (45)
  • 筆記x備忘 (77)
  • 閒談x雜記 (13)

贊助買咖啡

Facebook Instagram RSS

標籤

ai android cloudflare flutter git ios javascript linode linux MAC macos mis nginx php plugin QBQ!問題背後的問題 server work sublime sublime text vps vue.js vue3 What if What If? 如果這樣,會怎樣? wordpress 前端 原則 原子習慣 團隊,從傳球開始 團隊,從傳球開始:五百年都難以超越的 UCLA 傳奇教練伍登培養優越人才和團隊的領導心法 壓力測試 外掛 如果這樣,會怎樣?:胡思亂想的搞怪趣問 正經認真的科學妙答 心得 情緒 活動心得 灰階思考 約翰‧漢尼斯 股癌 自慢10 自慢10:18項修練 記錄 謝孟恭 讀書心得 這一生,你想留下什麼?

文章分類

  • 心得x體驗 (45)
  • 筆記x備忘 (77)
  • 閒談x雜記 (13)

近期文章

  • 於 MacOS 中,整合自然語言,自動化添加行事曆事件
  • 使用 deepwiki-open 針對程式碼產生 WIKI
  • 使用 Tailwind CLI 快速建立靜態 CSS 檔的基本步驟
  • Visual Studio Code 的 PHP CS Fixer 設定
  • MacOS 添加本地伺服器的 DNS

近期留言

  • 「Bolin Lai」於〈WordPress 之中藍新金流開啟後, Elementor 外掛有時會打不開的問題處理〉發佈留言
  • 「Jerry Lin」於〈WordPress 之中藍新金流開啟後, Elementor 外掛有時會打不開的問題處理〉發佈留言
  • 「JCL」於〈WordPress 之中藍新金流開啟後, Elementor 外掛有時會打不開的問題處理〉發佈留言

文章月曆

2025 年 6 月
日 一 二 三 四 五 六
1234567
891011121314
15161718192021
22232425262728
2930  
« 5 月    

© 2020 hipster.crazyjerry.studio - a blog about experience, notes and nonsense, by Jerry Lin.

No Result
View All Result
  • 首頁
  • 心得x體驗
  • 筆記x備忘
  • 閒談x雜記
  • 我的工具箱
  • 關於我

© 2020 hipster.crazyjerry.studio - a blog about experience, notes and nonsense, by Jerry Lin.