作者:zhanhailiang 日期:2014-11-03
git包括三个配置文件:
- /etc/gitconfig 文件:系统中对全部用户都普遍适用的配置。
若使用git config 时用' –system'选项,读写的就是这个文件。
- ~/.gitconfig 文件:用户文件夹下的配置文件仅仅适用于该用户。若使用git config 时用' –global'选项,读写的就是这个文件。
- 当前项目的git 文件夹中的配置文件(也就是工作文件夹中的.git/config 文件):这里的配置只针对当前项目有效。
每个级别的配置都会覆盖上层的同样配置,所以.git/config 里的配置会覆盖/etc/gitconfig 中的同名变量。
能够通过git config –list查看当前配置:
[root@~/wade/git/node-lessons]# git config --listcore.repositoryformatversion=0core.filemode=truecore.bare=falsecore.logallrefupdates=trueremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*remote.origin.url=https://github.com/alsotang/node-lessons.gitbranch.master.remote=originbranch.master.merge=refs/heads/master
我们也能够通过strace来检验git配置文件的载入顺序:
[root@~/wade/git/node-lessons]# strace git config --listexecve("/usr/bin/git", ["git", "config", "--list"], [/* 27 vars */]) = 0brk(0) = 0x151a000mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66c000access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)open("/etc/ld.so.cache", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=30968, ...}) = 0mmap(NULL, 30968, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f82cd664000close(3) = 0open("/lib64/libz.so.1", O_RDONLY) = 3read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 !\340\3611\0\0\0"..., 832) = 832fstat(3, { st_mode=S_IFREG|0755, st_size=91096, ...}) = 0mmap(0x31f1e00000, 2183696, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x31f1e00000mprotect(0x31f1e15000, 2093056, PROT_NONE) = 0mmap(0x31f2014000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x31f2014000close(3) = 0open("/lib64/libpthread.so.0", O_RDONLY) = 3read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340] \3611\0\0\0"..., 832) = 832fstat(3, { st_mode=S_IFREG|0755, st_size=145896, ...}) = 0mmap(0x31f1200000, 2212848, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x31f1200000mprotect(0x31f1217000, 2097152, PROT_NONE) = 0mmap(0x31f1417000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x31f1417000mmap(0x31f1419000, 13296, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x31f1419000close(3) = 0open("/lib64/libc.so.6", O_RDONLY) = 3read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\356\341\3601\0\0\0"..., 832) = 832fstat(3, { st_mode=S_IFREG|0755, st_size=1926680, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd663000mmap(0x31f0e00000, 3750152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x31f0e00000mprotect(0x31f0f8a000, 2097152, PROT_NONE) = 0mmap(0x31f118a000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18a000) = 0x31f118a000mmap(0x31f118f000, 18696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x31f118f000close(3) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd662000mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd661000arch_prctl(ARCH_SET_FS, 0x7f82cd662700) = 0mprotect(0x31f2014000, 4096, PROT_READ) = 0mprotect(0x31f1417000, 4096, PROT_READ) = 0mprotect(0x31f118a000, 16384, PROT_READ) = 0mprotect(0x31f0c1f000, 4096, PROT_READ) = 0munmap(0x7f82cd664000, 30968) = 0set_tid_address(0x7f82cd6629d0) = 25648set_robust_list(0x7f82cd6629e0, 0x18) = 0futex(0x7fffa73c199c, FUTEX_WAKE_PRIVATE, 1) = 0futex(0x7fffa73c199c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7f82cd662700) = -1 EAGAIN (Resource temporarily unavailable)rt_sigaction(SIGRTMIN, { 0x31f1205c60, [], SA_RESTORER|SA_SIGINFO, 0x31f120f710}, NULL, 8) = 0rt_sigaction(SIGRT_1, { 0x31f1205cf0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x31f120f710}, NULL, 8) = 0rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0getrlimit(RLIMIT_STACK, { rlim_cur=10240*1024, rlim_max=RLIM_INFINITY}) = 0brk(0) = 0x151a000brk(0x153b000) = 0x153b000getcwd("/root/wade/git/node-lessons", 4096) = 28stat(".git", { st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0access(".git/objects", X_OK) = 0access(".git/refs", X_OK) = 0lstat(".git/HEAD", { st_mode=S_IFREG|0644, st_size=23, ...}) = 0open(".git/HEAD", O_RDONLY) = 3read(3, "ref: refs/heads/master\n", 255) = 23read(3, "", 232) = 0close(3) = 0access("/etc/gitconfig", R_OK) = 0open("/etc/gitconfig", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=0, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66b000read(3, "", 4096) = 0close(3) = 0munmap(0x7f82cd66b000, 4096) = 0access("/root/.gitconfig", R_OK) = 0open("/root/.gitconfig", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=0, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66b000read(3, "", 4096) = 0close(3) = 0munmap(0x7f82cd66b000, 4096) = 0stat(".git", { st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0access(".git/config", R_OK) = 0open(".git/config", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=269, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66b000read(3, "[core]\n\trepositoryformatversion "..., 4096) = 269read(3, "", 4096) = 0close(3) = 0munmap(0x7f82cd66b000, 4096) = 0access("/etc/gitconfig", R_OK) = 0open("/etc/gitconfig", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=0, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66b000read(3, "", 4096) = 0close(3) = 0munmap(0x7f82cd66b000, 4096) = 0access("/root/.gitconfig", R_OK) = 0open("/root/.gitconfig", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=0, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66b000read(3, "", 4096) = 0close(3) = 0munmap(0x7f82cd66b000, 4096) = 0access(".git/config", R_OK) = 0open(".git/config", O_RDONLY) = 3fstat(3, { st_mode=S_IFREG|0644, st_size=269, ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66b000read(3, "[core]\n\trepositoryformatversion "..., 4096) = 269fstat(1, { st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82cd66a000write(1, "core.repositoryformatversion=0\n", 31core.repositoryformatversion=0) = 31write(1, "core.filemode=true\n", 19core.filemode=true) = 19write(1, "core.bare=false\n", 16core.bare=false) = 16write(1, "core.logallrefupdates=true\n", 27core.logallrefupdates=true) = 27write(1, "remote.origin.fetch=+refs/heads/"..., 56remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*) = 56write(1, "remote.origin.url=https://github"..., 63remote.origin.url=https://github.com/alsotang/node-lessons.git) = 63write(1, "branch.master.remote=origin\n", 28branch.master.remote=origin) = 28write(1, "branch.master.merge=refs/heads/m"..., 38branch.master.merge=refs/heads/master) = 38read(3, "", 4096) = 0close(3) = 0munmap(0x7f82cd66b000, 4096) = 0fstat(1, { st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0close(1) = 0munmap(0x7f82cd66a000, 4096) = 0exit_group(0) = ?
由此能够git配置文件载入顺序为/etc/gitconfig → ~/.gitconfig → .git/config。最后载入的同名配置会覆盖前者载入的配置。