git config 命令

转自http://blog.chinaunix.net/uid-15174104-id-3809952.html

引自:http://stackoverflow.com/questions/18062403/cannot-ping-google-com-from-ubuntu-terminal-behind-a-proxy-server

ping 了一天的网络,由于有代理proxy,都没有ping通,后来发现stackOverflow上的一个回答:


The usual reason for a proxy server is to isolate internal machines, and force them out through a central point in order to manage bandwidth, content and/or security concerns. Organizations who employ this mechanism will often disable routes from internal machines directly outside.

In this configuration, you are not truly connected to the internet, just the intranet which includes a server that proxies data from the internet to the intranet.

wget can work, if you set up the http_proxy environment variable, and perhaps add the --proxy-user and --proxy-password parameters. It is, in fact, a royal PITA.

ping will not work, if your network admin has disabled direct access to the larger network. To get ping working, you'll have to petition to have an exception for your workstation/server to be granted a direct route to the internet

       由于有代理所以ping外网ping不通,但是内网和网关都能ping通,但不影响访问Internet只要我们对各个application设置好proxy.

我们先来认识一下Git的三个最重要的配置文件,他们分别是/etc/gitconfig,${HOME}/.gitconfig, .git/config这三个配置文件都是Git运行时所需要读取的,但是它们分别作用于不同的范围。

  • /etc/gitconfig: 系统范围内的配置文件,适用于系统所有的用户; 使用 git config 时, 加 --system 选项,Git将读写这个文件。

  • ${HOME}/.gitconfig: 用户级的配置文件,只适用于当前用户; 使用 git config 时, 加 --global 选项,Git将读写这个文件。

  • .git/config: Git项目级的配置文件,位于当前Git工作目录下,只适用于当前Git项目; 使用 git config 时,不加选项( --system 和 --global  ),Git将读写这个文件。

每个级别的配置都会覆盖( override )上层的相同配置,覆盖的顺序是 .git/config  --> ${HOME}/.gitconfig --> /etc/gitconfig , 可越级覆盖。比如 .git/config 里的配置会覆盖 /etc/gitconfig 中的同名变量。在 Windows 系统上,Git 会寻找用户主目录下的 .gitconfig 文件。主目录即 ${HOME} 变量指定的目录,一般都是C:\Documents and Settings\${USER}。另外,你也可以使用 --file 或者 -f 来指定想要读写的配置文件。比如:

  • $ git config --file .git/config user.name                             # 查阅项目配置信息里的用户信息。
  • git config --file .git/config user.name "Harrison F"    # 将用户信息配置到项目的配置文件中。

       了解了这三个文件后,下面我们来看看git config的使用。当你在第一次安装完Git后,直接运行 git config --system --listgit config --global --list, 你将会分别看到下面的错误信息。没关系,这是因为你还没有配置过Git,Git的配置文件还没有生成。当你配置了一个信息后,相应的文件就会自动生成。

  1. harrison@ubuntu:~$ git config --global --list
  2. fatal: unable to read config file '/home/harrison/.gitconfig': No such file or directory
  3. harrison@ubuntu:~$ git config --system --list
  4. fatal: unable to read config file '/etc/gitconfig': No such file or directory
  • 用户信息(user.*)
 首先,需要配置的是你的用户名和Email地址。这两条配置非常重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,所以会随更新内容一起被永久纳入历史记录。
$ git config --global user.name "
Harrison F"
$ git config --global user.email harrison.f@gmail.com

使用了  --global  选项,所以,这些信息将被写入  ${HOME}/.gitconfig  中; 如果在特定的项目中,要使用其他的用户名或者Email地址,只需重新配置时去掉  --global 选项,新的信息将被写入  .git/config  中。 设置完这两条基本信息后,你应该可以提交更新了,但是为了让我们更方便的使用Git,我们还有几个重要的信息需要配置。
  • 文本编辑器(core.editor)
Git会在 需要你输入一些额外消息的时候自动调用一个外部文本编辑器给你使用。 默认会使用操作系统指定的默认编辑器,一般可能会是 Vi 或者 Vim。如果你有其他偏好,比如 Gedit的话,可以重新设置:
$ git config --global core.editor gedit
  • 字体颜色(color.*)
如果这个信息不配置,那么你与Git交互时,所有字体的颜色都将是默认系统的一个颜色,很难看,而也不方便我们看出更新和变化。
$ git config --global
 color.ui auto
$ git config --global color.status auto
$ git config --global color.branch auto
$ git config --global color.diff auto
$ git config --global color.interactive auto
  • 差异分析工具(merge.tool)
差异分析工具是用来解决合并冲突的,Git将在出现合并冲突时自动调用配置好的差异分析工具。
$ git config --global merge.tool vimdiff                  # 使用Vimdiff作为差异分析工具
  • 配置代理(http.proxy)
一般在公司内想要获取互联网上的Git项目,都要求设置HTTP代理。这里将设置最简单的HTTP代理。
$ git config --global http.proxy http://proxy.companyname.com:8080/ 

好了,我们这里学习最基本的Git配置和git config命令基本的用法。那么我们如果想删除一些不想要的配置怎么办呢?最直接办法就是编辑配置文件,但是这里还有更简单的命令来删除不想要的配置 信息。
  • 删除配置配置信息
$ git config --unset user.name                               删除具体的一条配置信息 (user.name="xxxxxx"将被删除)
$ git config --remove-section user                      # 删除一组配置信息 (user组的所有配置都将被删除) 
了解上面的这几个部分,那么git config就算基本掌握了,已经可以应付平常的使用。如果想要深入了解git config,请看git config的帮助手册。
$ git config                                                                  # 简短的帮助信息
$ git config --help                                                    # 详细的帮助手册
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值