星期日, 17 8 月, 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 年疫情才知道原來自己這是走在時代的潮流尖端。 感謝許多老闆和貴人相助,至今目前尚能存活,在台北街頭努力著。

近期文章

  • LLM 生成參數清單與說明
  • 使用 google 的 Gemini CLI 來製作字幕
  • 2025-07-29 社交模式檢討
  • 2025-07-25 社交模式檢討
  • 2025-07-12 N8N Workshop 筆記心得

分類

  • 心得x體驗 (47)
  • 筆記x備忘 (79)
  • 閒談x雜記 (15)

贊助買咖啡

Facebook Instagram RSS

標籤

android ci4 cloudflare Codeigniter codeigniter 4 flutter git ios linode linux MAC macos nginx php plugin QBQ!問題背後的問題 server work sublime sublime text vps vue.js vue3 What if What If? 如果這樣,會怎樣? wordpress 備份 原則 團隊,從傳球開始 團隊,從傳球開始:五百年都難以超越的 UCLA 傳奇教練伍登培養優越人才和團隊的領導心法 外掛 如果這樣,會怎樣?:胡思亂想的搞怪趣問 正經認真的科學妙答 媒體識讀 工作的原則 心得 意志力 活動心得 灰階思考 第三部分 第二部分 第四部分 股癌 自慢10 自慢10:18項修練 謝孟恭 讀書心得

文章分類

  • 心得x體驗 (47)
  • 筆記x備忘 (79)
  • 閒談x雜記 (15)

近期文章

  • LLM 生成參數清單與說明
  • 使用 google 的 Gemini CLI 來製作字幕
  • 2025-07-29 社交模式檢討
  • 2025-07-25 社交模式檢討
  • 2025-07-12 N8N Workshop 筆記心得

近期留言

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

文章月曆

2025 年 8 月
日 一 二 三 四 五 六
 12
3456789
10111213141516
17181920212223
24252627282930
31  
« 7 月    

© 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.