小知识:gitlab实践教程使用git config进行相关的配置操作

这篇文章根据实际碰到的一个问题来介绍一下git配置相关的内容。

命令: git config

使用git config进行相关的配置操作

配置文件

git在整体上,配置文件分为三级,结合优先级相关信息如下

%小知识:gitlab实践教程使用git config进行相关的配置操作-猿站网-插图

简单来说,优先级别离仓库越近越高,所以 项目级别 > 用户级别 > 系统级别。相同的设定同时出现时,优先级别高的会覆盖上层的配置。

配置检查

使用git config 不同的参数可以对如上三个不同的级别进行相关设定的检查

%小知识:gitlab实践教程使用git config进行相关的配置操作-1猿站网-插图

因为相同的设定有可能会产生覆盖,使用git config -l会列出git认为的最终设定信息

问题现象

很多客户端在自动生成.gitignore时会碰到问题,比如在如下git和os的版本下碰到了ng new动作发生的错误提示

环境信息

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
liumiaocn:angualr liumiao$ git –version
git version 2.15.0
liumiaocn:angualr liumiao$ uname -a
darwin liumiaocn 17.3.0 darwin kernel version 17.3.0: thu nov 9 18:09:22 pst 2017; root:xnu-4570.31.3~1/release_x86_64 x86_64
liumiaocn:angualr liumiao$
liumiaocn:angualr liumiao$ ng –version
_           _         ____ _   ___
/ \  _ __  __ _ _  _| | __ _ _ __   / ___| |  |_ _|
/ △ \ | _ \ / _` | | | | |/ _` | __|  | |  | |  | |
/ ___ \| | | | (_| | |_| | | (_| | |   | |___| |___ | |
/_/  \_\_| |_|\__, |\__,_|_|\__,_|_|    \____|_____|___|
|___/
angular cli: 1.7.3
node: 8.9.1
os: darwin x64
angular:
liumiaocn:angualr liumiao$

现象

?
1
2
3
4
5
6
7
8
9
liumiaocn:angualr liumiao$ ng new demo1 –skip-install
create demo1/readme.md (1021 bytes)
create demo1/.angular-cli.json (1240 bytes)
…省略
create demo1/src/app/app.component.ts (207 bytes)
error: could not expand include path ~/.gitcinclude
fatal: bad config line 44 in file /usr/local/git/etc/gitconfig
project demo1 successfully created.
liumiaocn:angualr liumiao$

配置信息

?
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
liumiaocn:angualr liumiao$ cat /usr/local/git/etc/gitconfig
[core]
excludesfile = ~/.gitignore
legacyheaders = false # >git 1.5
quotepath = false
[user]
#  name = your name
#  email = your@name
[mergetool]
keepbackup = true
[push]
default = simple # [ matching | simple ]
[color]
ui = auto
interactive = auto
[repack]
usedeltabaseoffset = true # >git 1.5
[alias]
s = status
a = !git add . && git status
au = !git add -u . && git status
aa = !git add . && git add -u . && git status
c = commit
cm = commit -m
ca = commit –amend # careful
ac = !git add . && git commit
acm = !git add . && git commit -m
l = log –graph –all –pretty=format:%c(yellow)%h%c(cyan)%d%creset %s %c(white)- %an, %ar%creset
ll = log –stat –abbrev-commit
lg = log –color –graph –pretty=format:%c(bold white)%h%creset -%c(bold green)%d%creset %s %c(bold green)(%cr)%creset %c(bold blue)<%an>%creset –abbrev-commit –date=relative
llg = log –color –graph –pretty=format:%c(bold white)%h %d%creset%n%s%n%+b%c(bold blue)%an <%ae>%creset %c(bold green)%cr (%ci) –abbrev-commit
d = diff
master = checkout master
spull = svn rebase
spush = svn dcommit
alias = !git config –list | grep alias\\. | sed s/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t => \\2/ | sort
[include]  # as of 1.7.10 https://github.com/git/git/commit/9b25a0b52e09400719366f0a33d0d0da98bbf7b0
path = ~/.gitcinclude
path = .githubconfig
path = .gitcredential
#[github]
#  user =
#  token =
[diff]
# git does copy/rename *detection*. if you want it to track copies/renames:
# http://stackoverflow.com/questions/1043388/record-file-copy-operation-with-git
# renames = copies
[diff “exif”]
textconv = exif
[credential]
helper = osxkeychain
liumiaocn:angualr liumiao$

原因

原因似乎是因为~的展开出现了问题,将~在设定文件中展开为全局的名称暂定解决了这个问题,但是结合上文可知,其实是将系统级的设定降到了用户级的处理方式。

修改方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
liumiaocn:angualr liumiao$ sudo cp /usr/local/git/etc/gitconfig /usr/local/git/etc/gitconfig.org
password:
liumiaocn:angualr liumiao$ echo $home
/users/liumiao
liumiaocn:angualr liumiao$ echo ~
/users/liumiao
liumiaocn:angualr liumiao$ sudo vi /usr/local/git/etc/gitconfig
liumiaocn:angualr liumiao$
liumiaocn:angualr liumiao$ diff /usr/local/git/etc/gitconfig /usr/local/git/etc/gitconfig.org
2c2
<  excludesfile = /users/liumiao/.gitignore
>  excludesfile = ~/.gitignore
44c44
<  path = /users/liumiao/.gitcinclude
>  path = ~/.gitcinclude
liumiaocn:angualr liumiao$

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对服务器之家的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/liumiaocn/article/details/81068478

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Alpine镜像中telnet转移至busybox-extras

2023-4-4 15:42:14

建站知识

小知识:docker私库Harbor的架构与组件说明

2023-4-4 15:56:46

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索