Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

20.11. git config

20.11.1. git config

$ git config --file config http.receivepack true
	

20.11.2. 查看配置

		
Neo-iMac:workspace neo$ git config --list 
credential.helper=osxkeychain
user.name=Neo Chen
user.email=netkiller@msn.com
user.signingkey=netkiller@msn.com
gpg.program=gpg
commit.gpgsign=true			
		
		

20.11.3. 编辑配置

		
git config --global --edit
		
		
		
git config --edit
		
		

20.11.4. 替换配置项

		
$  git config --global --replace-all user.email "输入你的邮箱"
$  git config --global --replace-all user.name "输入你的用户名"			
		
		

20.11.5. 配置默认分之

		
git config --global init.defaultBranch <名称>			
		
		

20.11.6. GPG签名

		
开启GPG签名:

git config commit.gpgsign true

关闭:

git config commit.gpgsign false			
		
		

20.11.7. core.sshCommand

git 默认使用 id_rsa,指定私钥方法是:

		
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"
git pull
git push
		
		

		
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example -F /dev/null" git clone git@github.com:netkiller/netkiller.github.io.git		
		
		

20.11.8. fatal: The remote end hung up unexpectedly

error: RPC failed; result=22, HTTP code = 413 | 18.24 MiB/s
fatal: The remote end hung up unexpectedly
		
git config http.postBuffer 524288000
		

20.11.9. 忽略 SSL 检查

使用自颁发 ssl 证书时需要开启,否则无法 clone 和 push

		
export GIT_SSL_NO_VERIFY=true			
		
		

		
git config http.sslVerify "false"  			
		
		

20.11.10. 配置忽略合并文件

从一个分支向另一个分支合并,有时我们不想覆盖某个文件。

		 
neo@MacBook-Pro-M2 ~/netkiller (dev)> git config merge.ours.driver true
		
		

创建 .gitattributes 文件

		
neo@MacBook-Pro-M2 ~/netkiller (office)> cat .gitattributes
src/main/resources/bootstrap.yml merge=ours
		
		

全局配置

		 
git config --global merge.ours.driver true
		
		

20.11.11. .gitignore

find ./ -type d -empty | grep -v \.git | xargs -i touch {}/.gitignore
		

20.11.12. .gitattributes

20.11.12.1. SVN Keywords

			
Example:

$ echo '*.txt ident' >> .gitattributes
$ echo '$Id$' > test.txt
$ git commit -a -m "test"

$ rm test.txt
$ git checkout -- test.txt
$ cat test.txt			
			
			
			
			
			
			
			
			

20.11.12.2. 设置文件换行符

开发者使用不同的操作系统,不同的开发工具,保存的文件换行符有三种,CR、LF、CRLF,也就是回车CR和换行的组合。

解决方案,在项目根目录下创建 .gitattributes 文件

			 
*.js    eol=lf
*.jsx   eol=lf
*.json  eol=lf
			
			

20.11.13. 配置模版目录

配置模版之后,克隆项目会自动创建模版下的目录和文件

		 
mkdir -p ~/workspace/template/hooks				
		
		

配置模版目录

		 
git config --global init.templatedir ~/workspace/template/		
		
		

创建文件

		 
curl -s https://gitlab.ejiayou.com/chenjingfeng/zentao/-/raw/master/commit-msg -o ~/workspace/hooks/commit-msg
chmod +x ~/workspace/hooks/commit-msg
		
		

现在执行 git clone 之后你会发现 .git/hooks 目录会产生一个 commit-msg 文件