git筆記

設置環境變量GIT_CURL_VERBOSE=1可以讓git指令輸出詳細信息

刪除多余空格

git rebase HEAD~ --whitespace=fix

設置代理

git config --global http.proxy ****
git config --global https.proxy ****
git config --global --unset https.proxy? 取消代理

設置用戶

git config --global user.name "****"
git config --global user.password "*****"
git config --unset user.password? 重置密碼

檢查歷史版本

特定文件的變動歷史? git log -p file_path
查看特定commit時點文件內容? ?git show REVISION:path/to/file

本地分支與遠程分支

建立關聯 git branch -u [remote_branch] [local_branch] 其中-u是--set-upstream-to的縮寫
取消關聯 git branch --unset-upstream
拉取遠程代碼? git pull <remote_host> <remote_branch>:<local_branch>? 可以省略分支,這樣自動更新本地追蹤的遠程分支
向gerrit推送更新? ?git push [repo name] HEAD:refs/for/[branch name]
????????例如git push origin HEAD:refs/for/next 將本地HEAD所在分支推送到origin端的next分支,注意其中的refs/for是必須的,如果省略git會默認解析成refs/head,而對gerrit來說推送到refs/head/***意味著不經過審核直接提交。
????????“origin” 是運行 git clone 時默認的遠程倉庫名字。 如果運行 git clone -o booyah,那么默認的遠程分支名字將會是 booyah/master。
? ? ? ? 如果省略HEAD:部分,則自動選擇本地同名分支進行推送
將遠程分支同步到本地??git remote update origin --prune

使用gvim提交

git config --global core.editor "gvim -f"

遞歸忽略文件

在.gitignore中用"**"可以代表任意路徑,例如"**/*.swp"可以忽略工程根目錄和任意子目錄下的swp后綴文件。

彩色信息

git config --global color.ui true

git push免密碼

如果遠程倉庫是git url,需要用ssh key。如果遠程倉庫是http url,在用戶主目錄創建.git-credentials,寫入
https://{username}:{password}@{倉庫網址}
然后執行git config --global credential.helper store

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。