Skip to main content

Tedshd's Dev note

Category: Git

git hooks

# git hooks 和其他版本控制系統一樣,當某些重要事件發生時,Git 有方法可以觸發自訂腳本。有兩組掛鉤(hooks):用戶端和伺服器端。用戶端掛鉤用於用戶端的操作,如提交和合併。伺服器端掛鉤用於 Git 伺服器端的操作,如接收被推送的提交。你可以為了各種不同的原因使用這些掛鉤,下面會講解其中一些。 git hooks 簡單的說就是在進行版本控管時可以再額外多做一些事 Refer - Git 客製化 - Git Hooks 在以前我們公司在前端開發上是用前輩大大寫好的 hook 做一些事 但前輩大大們陸續離開後, 架構又改了 新專案沒法用原有的 hook 所以只好跳進來寫 hook 了 ## 可以用來幹嘛? ### Client side lint 檢查 coding style 檢查 完善要推的 code 做自動化測試 … ### Server side deploy code to production auto build … ## 打算用來幹嘛? 身為一隻前端攻城獅, 只要顧好 client side 就好了 預計完成 phpcs jshint image trans to png8 ? multi-lang file check ? ...

Git - GitHub gh-pages

# Git - GitHub gh-pages 有時在 GitHub 上亂晃 常常發現一個問題就是有一些很有趣的前端實作, 或別人寫的一些功能沒有所謂的 demo page(當然有些是不需要 demo page) 我不知道是把 GitHub 當成備份的 codebase 或是覺得 demo 不重要所以沒放, 又或者是根本不知道要怎麼放 But 這都不重要 其實 GitHub 提供一個 gh-pages 的 branch(或者說是功能)可以讓我們這些前端攻城獅快速的建出個 demo page(但不包含後端功能) ## 如何使用? ### 1. 從 master 建出名為 gh-pages 的 branch git branch gh-pages ## 2. 切到 gh-pahes 的 branch git checkout gh-pages ## 3. 把 gh-pages git push 上 GitHub git push 因為剛建出新的 branch, 該 branch 還未在 GitHub 上所以會提示你要用 git push --set-upstream origin gh-pages ...

Git -Tip & Note

# Git -Tip & Note ## git pull 出現 CONFLICT 要回復到 pull 之前 git reset --hard <commit id> ## 強制 push 取代 remote git push -f ## 取消 merage (須知道 merage 前的 commit id) git reset --hard <commit id> ## 拉 remote 的新 branch 到 local(local 不存在該 branch) git checkout --track -b <local new branch> <remote branch> ## 不小心把 remote & local 的 branch 刪掉 先用 git reflog git reflog # show # df4bb25 HEAD@{0}: checkout: moving from master to dev # df4bb25 HEAD@{1}: checkout: moving from webtv_dev to master # 9e920fb HEAD@{2}: commit: [Dev] Modify keycode to keyboard. ...

Git - command

# Git - command git status # 查看修改哪些檔案 git diff # 比對修改了的地方與上一個 commit 有何不同 git diff <file> # 比對修改的檔案與上一個 commit 有何不同 git diff <old commit id>..<new commit id> # 比對不同 commit id 的檔案差異 git coheckout -- <file> # 把檔案回復到修改前的樣子 git add <file> # 加入要 commit 的檔案 git rm <file> # 移除檔案(有 commit 過的檔案要移除, rm <file> 之後要執行的指令) git reset HEAD <file> # 把 git add 之後的檔案回復到 git add 前 git commit -m '註解' # or git commit # commit 檔案進入版本控管系統 git commit --no-verify # 不驗證 commit git log # git commit log 紀錄 git log -p # 詳細的log紀錄(修改哪些部分) git blame <file> # 查看修改的紀錄 git clone <repository> # 拉 repository 下來到 local 端 git branch <branch name> # 建立一個 local 端的 branch git checkout <branch> # 切換到該 branch git branch # 查看本地端的 branch git branch -r # 查看 remote 端的 branch git stash # 檔案 不commit 跳 branch (暫存) git stash pop # 回復檔案不 commit 狀態(讀回) git branch -d <local branch> # 刪除本地端的 branch git branch -r -d <remote branch> # 刪除 remote 端的 branch git checkout --track -b <local branch> origin/<remote branch> # 將遠端的 branch 並在 local 建立 branch Refer Refer ...

Git - 使用別人的 repository

# Git - 使用別人的 repository in GitHub sample use javascript-htmlspecialchars use SSH git clone git@github.com:tedshd/javascript-htmlspecialchars.git // use SSH 單純的 clone 別人的 repository 只是只能使用它 如 commit 之後是無法 push 上去, 因為不是這 repository 的擁有者 只要進去該 repository 的 .git/config 只要看見 [remote "origin"] url = git@github.com:tedshd/javascript-htmlspecialchars.git url 中 git@github.com: 之後不是自己的 GitHub 帳號就代表是無法 push 的 就算在這改成自己的 GitHub 帳號也是無用的 因為沒有該 repository 在自己的 repositories 中 ## 把別人的 repository 改成自己用的 fork 一份到自己的 GitHub 從自己的 repositories git clone fork 來的 repository 之後 commit 就可以 push 到自己 fork 的 repository ...

gitconfig

# gitconfig Mac gitconfig path ~/.gitconfig [user] name = tedshd email = tedshd@gmail.com [alias] st = status co = checkout br = branch d = difftool [color] diff = auto status = auto branch = auto ui = auto [credential] helper = osxkeychain [push] default = simple [core] editor = vim [diff] tool = vimdiff [difftool] prompt = false vim diff git d terminal git diff ...