git配置config文件


1.Git有一个工具被称为git config,它允许你获取和设置变量;这些变量可以控制Git的外观和操作的各个方面。这些变量以等级的不同可以被存储在三个不同的位置:

(1) /etc/gitconfig 文件:包含了适用于系统所有用户和所有库的值。如果你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。

(2) ~/.gitconfig 文件 :具体到你的用户。你可以通过传递--global 选项使Git明确的读或写这个特定的文件。

(3) .git/config位于git目录的config文件,特定指向该单一的库。如果git config 时不加--system 也不加--global选项,那么只作用于当前的git版本库,配置产生的修改都体现在.git/config文件中

三个config文件是逐级覆盖的关系,具体的覆盖非具体的。

2.例子
(1) 用户标识配置
$ git config --global user.name "John Doe" //user.name就是对[user]下的name进行配置
$ git config --global user.email johndoe@example.com

$ cat ~/.gitconfig
[user]
email = johndoe@example.com
name = John Doe
...

这里的修改是针对这个用户的所有git版本库的,若不加--global可以就是只针对某一个具体的版本库起作用,修改体现在.git/config下。

3.更多例子
$ git config --global core.editor emacs 指定你的编辑器
$ git config --global merge.tool vimdiff 指定你的比较工具(Your Diff Tool)
$ git config --list 检查你的设置(Checking Your Settings)
$ git help config 获取帮助(Getting help)

4.分别移除各个等级的一个配置项
git config --unset user.name
git config --unset --global user.name
git config --unset --system user.name

5.移除一组配置项
git config --remove-section color

6. git config get user.name  获取一个属性的值,当然也可以直接cat上面的config文件。

7.我的.gitconfig文件

复制代码
# cat ~/.gitconfig 
[user]
        name = xxx
        email = xxx@xxx.com
[alias]
        st = status
        ci = commit
[commit]
[core]
        editor = vim
[color]
        ui = auto
[push]
        default = matching
[alias] 
        st = status    
        co = checkout
        ci = commit
        br = branch
        lo = log --oneline
        la = log --author
        lg = log --graph
        dc = diff --cached
        cp = cherry-pick
        dir = rev-parse --git-dir
复制代码

补充:

bc = branch --contains  //git branch --contains <hash> 查看包含hash提交的分支。

 

8. 若变更服务器了,可以使用scp命令来同步git配置(包括私钥) 和其它一些配置

(1) 假设两台机器IP分别为:A.104.238.161.75,B.43.224.34.73,你要从A服务器变更为B服务器,那么需要将A服务器上与git相关的配置文件拷贝到B服务器相同目录下,执行:

scp -r ~/{.ssh,.netrc,.gitconfig} <your job number>@43.224.34.73:<home path>

 

posted on   Hello-World3  阅读(2846)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示