實用的 Git 小撇步 Useful tricks for using Git

Remove all .pyc or .xxx files: 移除附檔名為 .pyc
find . -name "*.pyc"; -exec git rm -f {} \;

Remove a file in remote repository without deleting local file: 移除遠端 repo 中檔案, 但是不移除本機端檔案
git rm --cached your_file_here

Set ignore file:
git config --global core.excludesfile ~/.gitignore_global

Ignore SSL verification: 忽略 SSL 認證
env GIT_SSL_NO_VERIFY=true git command
or set to config:
git config http.sslVerify "false"

Stash your code: 將尚未 commit 的檔案暫存
git stash

Get sources after commit id: 取出某個 commit 後的某個資料夾下所有的檔案
git checkout 336e1731fd8591c712d029681392e5982b2c7e6b src/abc/*

Avoiding annoying merge commits: 多人分工開發時避免產生多次無謂的 merge commits
git pull --rebase origin master

Avoiding to merge or commit your customised configs: 自己測試時本機更改的 config 不想要 commit 或是 merge
git update-index --assume-unchanged [filepath]

Putting back and tracking the files above: 將上述排除的檔案加回到追蹤檔案
git update-index --no-assume-unchanged [filepath]

留言