git config

git

git工作流程

git工作流程

git配置

/etc/gitconfig 文件:系統中對所有用戶都普遍適用的配置。若使用 git config 時用 –system 選項,讀寫的就是這個文件。
~/.gitconfig 文件:用戶目錄下的配置文件只適用於該用戶。若使用 git config 時用 –global 選項,讀寫的就是這個文件。
當前項目的 Git 目錄中的配置文件(也就是工作目錄中的 .git/config 文件):這裏的配置僅僅針對當前項目有效。每一個級別的配置都會覆蓋上層的相同配置,所以 .git/config 裏的配置會覆蓋 /etc/gitconfig 中的同名變量。

查看配置信息
要檢查已有的配置信息,可以使用 git config -l 命令:
有時候會看到重複的變量名,那就說明它們來自不同的配置文件(比如 /etc/gitconfig 和 ~/.gitconfig),不過最終 Git 實際採用的是最後一個。

配置命令

#1. 設置用戶名郵箱 
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

#2. https替代git協議
$ git config --global url."https://".insteadof "git://"
$ git config --global url."https://github.com/".insteadof "[email protected]:"

#3. 設置代理 
$ git config --global http.proxy socks5://127.0.0.1:1080
$ git config --global https.proxy socks5://127.0.0.1:1080
取消:
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy

#4. 取消crlf自動轉換爲lf
$ git config --global core.autocrlf false

#5. 使用simple模式(只推送當前分支到遠端)而不是matching(推送本地所有分支到遠端)
$ git config --global push.default simple

#6. Git提交時發生SSL certificate problem錯誤的解決方法
$ git config --global http.sslVerify false

#7. Git提交時發生 error: RPC failed;
解決辦法,把git的buffer擴充到500M:
$ git config http.postBuffer 524288000

#8. 使用以下命令生成SSH Key:
$ ssh-keygen -t rsa -C "[email protected]"
後面的[email protected]改爲你在github上註冊的郵箱,
之後會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行。
成功的話會在~/下生成.ssh文件夾,進去,打開id_rsa.pub,複製裏面的key。
-->
回到github上,進入 Account Settings(賬戶配置),
左邊選擇SSH Keys,Add SSH Key,title隨便填,粘貼在你電腦上生成的key。

參考:

http://segmentfault.com/a/1190000002435496

操作

git工作暫存版本庫

  1. 當執行 git checkout . 或者 git checkout -- <file> 命令時,會用暫存區全部或指定的文件替換工作區的文件。這個操作很危險,會清除工作區中未添加到暫存區的改動。

  2. 當執行 git checkout HEAD . 或者 git checkout HEAD <file> 命令時,會用 HEAD 指向的 master 分支中的全部或者部分文件替換暫存區和以及工作區中的文件。這個命令也是極具危險性的,因爲不但會清除工作區中未提交的改動,也會清除暫存區中未提交的改動。

  3. 當執行 git reset HEAD 命令時,暫存區的目錄樹會被重寫,被 master 分支指向的目錄樹所替換,但是工作區不受影響。

git提交小技巧

git add -A = git add . + git add -u

git add -A # stages All
git add .  # stages new and modified, without deleted
git add -u # stages modified and deleted, without new

關於Crlf和lf的那些事:

(fatal: CRLF would be replaced by LF )

CR回車 LF換行Windows/Dos CRLF \r\n
Linux/Unix LF \n
MacOS CR \r
解決方法是:打開命令行,進行設置,如果你是在Windows下開發,建議設置autocrlf爲true。
2014/08/20 補充:如果你文件編碼是UTF8並且包含中文文字,那還是把autocrlf設置爲false,並且把所有文件轉換爲Linux編碼(即LF\n),開啓safecrlf檢查。

一、AutoCRLF

#提交時轉換爲LF,檢出時轉換爲CRLF
git config --global core.autocrlf true   

#提交時轉換爲LF,檢出時不轉換
git config --global core.autocrlf input   

#提交檢出均不轉換
git config --global core.autocrlf false

二、SafeCRLF

#拒絕提交包含混合換行符的文件
git config --global core.safecrlf true   

#允許提交包含混合換行符的文件
git config --global core.safecrlf false   

#提交包含混合換行符的文件時給出警告
git config --global core.safecrlf warn

bower

1. 代理
在工程或用戶主目錄下,新建一個.bowerrc文件,文件內容是JSON格式:

"proxy" : "socks5://127.0.0.1:1080",
"https-proxy": "socks5://127.0.0.1:1080"

2. shorthand-resolver
默認值:

git://github.com/{{owner}}/{{package}}.git

如果網絡不通,或不能使用git,可以將其修改爲

"shorthand-resolver": "https://github.com/{{owner}}/{{package}}.git"

綜合

.bowerrc

"proxy" : "socks5://127.0.0.1:1080",
"https-proxy": "socks5://127.0.0.1:1080",
"shorthand-resolver": "https://github.com/{{owner}}/{{package}}.git"

centos安裝git

1、最新git源碼下載地址:

https://github.com/git/git/releases
https://www.kernel.org/pub/software/scm/git/
可以手動下載下來在上傳到服務器上面

2 移除舊版本git

centos自帶Git,7.x版本自帶git 1.8.3.1(應該是,也可能不是),
安裝新版本之前需要使用yun remove git卸載(安裝後卸載也可以)。

[root@Git ~]# git --version    ## 查看自帶的版本
git version 1.8.3.1
[root@Git ~]# yum remove git   ## 移除原來的版本

3 安裝所需軟件包

[root@Git ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y
[root@Git ~]# yum install gcc-c++ perl-ExtUtils-MakeMaker autoconf automake libtool -y

下載&安裝

[root@Git ~]# cd /usr/src
[root@Git ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.7.3.tar.gz

5 解壓

[root@Git ~]# tar xf git-2.7.3.tar.gz

6 配置編譯安裝

[root@Git ~]# cd git-2.7.3
[root@Git ~]# make configure
[root@Git ~]# ./configure --prefix=/usr/git ##配置目錄
[root@Git ~]# make profix=/usr/git
[root@Git ~]# make install

7 加入環境變量

[root@Git ~]# echo "export PATH=$PATH:/usr/git/bin" >> /etc/profile
[root@Git ~]# source /etc/profile

8 檢查版本

[root@Git git-2.7.3]# git --version 
git version 2.7.3

參考文檔:

Git 安裝配置 | 菜鳥教程

Git教程 | 菜鳥教程

git - 簡易指南

發佈了43 篇原創文章 · 獲贊 12 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章