設(shè)置環(huán)境變量GIT_CURL_VERBOSE=1可以讓git指令輸出詳細(xì)信息
刪除多余空格
git rebase HEAD~ --whitespace=fix
設(shè)置代理
git config --global http.proxy ****
git config --global https.proxy ****
git config --global --unset https.proxy? 取消代理
設(shè)置用戶
git config --global user.name "****"
git config --global user.password "*****"
git config --unset user.password? 重置密碼
檢查歷史版本
特定文件的變動歷史? git log -p file_path
查看特定commit時點(diǎn)文件內(nèi)容? ?git show REVISION:path/to/file
本地分支與遠(yuǎn)程分支
建立關(guān)聯(lián) git branch -u [remote_branch] [local_branch] 其中-u是--set-upstream-to的縮寫
取消關(guān)聯(lián) git branch --unset-upstream
拉取遠(yuǎn)程代碼? git pull <remote_host> <remote_branch>:<local_branch>? 可以省略分支,這樣自動更新本地追蹤的遠(yuǎn)程分支
向gerrit推送更新? ?git push [repo name] HEAD:refs/for/[branch name]
????????例如git push origin HEAD:refs/for/next 將本地HEAD所在分支推送到origin端的next分支,注意其中的refs/for是必須的,如果省略git會默認(rèn)解析成refs/head,而對gerrit來說推送到refs/head/***意味著不經(jīng)過審核直接提交。
????????“origin” 是運(yùn)行 git clone 時默認(rèn)的遠(yuǎn)程倉庫名字。 如果運(yùn)行 git clone -o booyah,那么默認(rèn)的遠(yuǎn)程分支名字將會是 booyah/master。
? ? ? ? 如果省略HEAD:部分,則自動選擇本地同名分支進(jìn)行推送
將遠(yuǎn)程分支同步到本地??git remote update origin --prune
使用gvim提交
git config --global core.editor "gvim -f"
遞歸忽略文件
在.gitignore中用"**"可以代表任意路徑,例如"**/*.swp"可以忽略工程根目錄和任意子目錄下的swp后綴文件。
彩色信息
git config --global color.ui true
git push免密碼
如果遠(yuǎn)程倉庫是git url,需要用ssh key。如果遠(yuǎn)程倉庫是http url,在用戶主目錄創(chuàng)建.git-credentials,寫入
https://{username}:{password}@{倉庫網(wǎng)址}
然后執(zhí)行g(shù)it config --global credential.helper store