Leif160519的blog Leif160519的blog

——————

目录
git:一系列骚操作
/  

git:一系列骚操作

一、配置多用户

1.按工程配置多用户

  • a. /etc/gitconfig 系统配置,对所有用户生效

  • b. ~/.gitconfig 用户配置,仅对当前用户生效

    git config --global user.name "yourname"
    git config --global user.email "yourEmail"
    
  • c. projectRootPath/.git/config项目根目录配置,仅对当前项目生效,进入工程根目录执行

    git config user.name "yourname"
    git config user.email "yourEmail"
    

    三层优先级c-b-a,项目少还行,多的话很头疼,所以就有了下面这个方法

2.按目录配置多用户

git 2.13.0版本包含了一个新功能includeIf配置,可以吧匹配的路径使用对应的配置用户名和邮箱

~/下放三个配置文件

  • .gitconfig 全局通用的配置文件
  • .gitconfig-github github上的配置文件
  • .gitconfig-gitlab gitlab上的配置文件

.gitconfig里的内容是,主要通过includeIf配置匹配不同的目录映射到不同的配置文件上

[core]
        editor = vim
        quotepath = false
[includeIf "gitdir:/data/workspace/gitlab/"]
    path = .gitconfig-gitlab
[includeIf "gitdir:/data/workspace/github/"]
    path = .gitconfig-github

github配置文件:~/.gitconfig-github

[user]
        email = yourEmail-github
        name = yourname-github

gitlab配置文件:~/.gitconfig-gitlab

[user]
        email = yourEmail-gitlab
        name = yourname-gitlab

注意:

  • 文件~/.gitconfig里面的includeIf后面的path最后需要/结尾
  • 文件~/.gitconfig里面原有的user部分需要删除
  • 个人工程目录和公司工程目录需要要求是非包含关系,就是这两个工程目录配置路径不可以是父子关系。

3.参考

二、进行空白提交

默认情况下,git是不允许空白提交的,提交之前必须add一下变更的文件然后git commit -m "msg"

可以使用--allow-empty进行没有文件变更前提下的空白提交

git commit --allow-empty -m "xxx"

修改空白提交的信息

git commit --amend --allow-empty

重置上一个空白提交的作者

git commit --amend --allow-empty --reset-author

三、设置代理

1.配置socks5或者http代理

git config --global http.proxy http://127.0.0.1:3128
git config --global http.proxy socks5://127.0.0.1:1080
  • 注意:没有https.proxy写法

2.对于使用git@协议的,可以配置socks5或者http代理

方法:在~/.ssh/config 文件后面添加几行,没有该文件的可以新建一个

Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p # socks5代理
ProxyCommand nc -X connect -x 127.0.0.1:3128 %h %p # http代理

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题git:一系列骚操作
作  者Leif160519
出  处https://github.icu/articles/2021/05/26/1622019260323.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!