git中的配置文件(/etc/gitconfig,${HOME}/.gitconfig,.git/config)

參考自:https://blog.csdn.net/u013756604/article/details/78408586?utm_source=blogxgwz0

Git中有三個重要的配置文件:他們分別是1/etc/gitconfig,2${HOME}/.gitconfig,3.git/config。這三個配置文件都是Git運行時所需要讀取的,但是它們分別作用於不同的範圍。

  • /etc/gitconfig: 系統範圍內的配置文件,適用於系統所有的用戶; 使用 git config 時, 加 --system 選項,Git將讀寫這個文件。
  • ${HOME}/.gitconfig: 用戶級的配置文件,只適用於當前用戶; 使用 git config 時, 加 --global 選項,Git將讀寫這個文件。
  • .git/config: Git項目級的配置文件,位於當前Git工作目錄下,只適用於當前Git項目; 使用 git config 時,不加選項( --system 和 --global ),Git將讀寫這個文件。

修改用戶信息(用戶名和郵箱)
首先,需要配置的是你的用戶名和Email地址。這兩條配置非常重要,每次 Git 提交時都會引用這兩條信息,說明是誰提交了更新,所以會隨更新內容一起被永久納入歷史記錄。

git config --global user.name TangShengqin
git config --global user.email [email protected]

設置完這兩條基本信息後,纔可以提交更新。

設置文本編輯器

 git config --global core.editor vim # 默認是使用vi或者vim
 git config --global core.editor gedit # 如果能使用圖形化的編輯器的話

配置代理(http.proxy)
一般在公司內想要獲取互聯網上的Git項目,都要求設置HTTP代理。這裏將設置最簡單的HTTP代理。

git config --global http.proxy http://proxy.companyname.com:8080/ 

本機上倉庫/.git/config下的內容:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = https://github.com/TangShengqin/EasyFigure.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

本機上/home/tsq/.gitconfig文件內容:

[user]
	email = [email protected]
	name = TangShengqin
[push]
	default = simple
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章