這篇文章根據(jù)實(shí)際碰到的一個(gè)問(wèn)題來(lái)介紹一下git配置相關(guān)的內(nèi)容。
命令: git config
使用git config進(jìn)行相關(guān)的配置操作
配置文件
git在整體上,配置文件分為三級(jí),結(jié)合優(yōu)先級(jí)相關(guān)信息如下
簡(jiǎn)單來(lái)說(shuō),優(yōu)先級(jí)別離倉(cāng)庫(kù)越近越高,所以 項(xiàng)目級(jí)別 > 用戶(hù)級(jí)別 > 系統(tǒng)級(jí)別。相同的設(shè)定同時(shí)出現(xiàn)時(shí),優(yōu)先級(jí)別高的會(huì)覆蓋上層的配置。
配置檢查
使用git config 不同的參數(shù)可以對(duì)如上三個(gè)不同的級(jí)別進(jìn)行相關(guān)設(shè)定的檢查
因?yàn)橄嗤脑O(shè)定有可能會(huì)產(chǎn)生覆蓋,使用git config -l會(huì)列出git認(rèn)為的最終設(shè)定信息
問(wèn)題現(xiàn)象
很多客戶(hù)端在自動(dòng)生成.gitignore時(shí)會(huì)碰到問(wèn)題,比如在如下git和os的版本下碰到了ng new動(dòng)作發(fā)生的錯(cuò)誤提示
環(huán)境信息
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$
現(xiàn)象
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$
配置信息
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$
原因
原因似乎是因?yàn)椤恼归_(kāi)出現(xiàn)了問(wèn)題,將~在設(shè)定文件中展開(kāi)為全局的名稱(chēng)暫定解決了這個(gè)問(wèn)題,但是結(jié)合上文可知,其實(shí)是將系統(tǒng)級(jí)的設(shè)定降到了用戶(hù)級(jí)的處理方式。
修改方法
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$
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接