我@嘉義
336 字
2 分鐘
Git Basics
遷移自 HackMD
也請參考:GitHub CLI
版本控管
Undo Uncommitted Changes
This will unstage all files you might have staged with git add:
git resetThis will revert all local uncommitted changes (should be executed in repo root):
git checkout .You can also revert uncommitted changes only to particular file or directory:
git checkout [some_dir|file.txt]Ignoring Files
REMOVE ALL SPECIFIED IN .gitignore FROM REPOSITORY
git rm --cached `git ls-files -i -c --exclude-from=.gitignore`雜項
<ERROR> RPC Failed
本解決方案的原理是將推送的大小限制調大,避免因為push/pull的流量太大而讓Git產生buffer塞爆的問題。
git config --global http.postBuffer 524288000Show Non-Alphabetic Characters
在Git剛設定完時,如果推送了非英文的內容,commit log或者status就可能會出現「亂碼」。不過別緊張,有可能是Git的設定預設值造成的。
git config --global core.quotepath false這個設定的意思是「要不要把非標準字元輸出為代碼」。設定為否的話,系統才會嘗試把原本的字元顯示出來。至於如果還是亂碼,那就要去研究locale是否設定妥當。
遠端控管
Push Local Repo to GitHub
首先要先在GitHub開啟一個空的repo,名稱隨意,不過建議使用跟本地repo差不多的名字。
然後,在本地的commit:
cd LOCAL_REPO_DIR/git init .git config --global --add safe.directory $(pwd -P)git add .git commit -m "init"設定&推送:
git remote add origin <ORIGIN_URL>git push --set-upstream origin master