chenkehao 发表于 2018-1-13 13:58:34

mac下的git的安装与简单的配置

  git 本地操作
  git 简单介绍
  1、Git是分布式的SCM,SVN是集中式的
  2、Git每一个历史版本号存储完整的文件,SVN存储文件差异
  3、Git可离线完毕大部分操作,SVN则相反
  4、Git有着更优雅的分支和合并实现
  5、Git有更强的撤销改动和改动版本号历史的能力
  6、Git速度更快,效率更高
  一、mac 下下载 git 地址
  http://git-scm.com
  http://sourceforge.net/projects/git-osx-installer/
  1.切换最新版本号。自己喜欢的版本号
  输入 : which-a git
  2.显示我们用的是哪个版本号的git
  git-- version
  3.确保安装是刚刚下载的版本号
  vim .bash_profile
  输入:export PATH=/usr/local/git/bin:$PATH
  加载一下source .bash_profiel
  再次 看一下 刚刚改动是否成功:
  hairongchen:~$git —version
  显示:git version2.2.1
  二、配置git 输入命令自己主动完毕
  1.进入http://github.com/git/git
  下载git 包,并解压到一个位置
  2.在终端进入刚解压的位置
  再进入 contrib/completion/目录
  发现有四个文件,而以下这两个文件是我们须要的
  git-completion.bash
  git-prompt.sh
  把上面这两个文件复制到当前用户home文件夹下
  cp git-completion.bash ~/
  cp git-prompt.sh~/
  改动.bash_profile
  vim .bash_profile
  输入下面内容
  # copy contrib/copmletion/git-completion.bash to your home directory and source it
  #Linux users should add the line below to your .bashrc
  . ~/git-completion.bash
  #copy contrib/completion/git-prompt.sh to your home directory and source it
  #Linux users should add the line below to your .bashrc
  . ~/git-prompt.sh
  export GIT_PS1_SHOWDIRTYSTATE=1
  # export PS1='\w$(__git_ps1 " (%s)")\$'
  export PS1='\u:\W$(__git_ps1 " (%s)")\$ '
  上面这两个文件主要是在git 输入命令时能够自己主动完毕及有内容提示
  ,防止输入命令出错
  保存退出并source 一下.bash_profile
  3.此时我们输入git confi并按 tab键。就会自己主动补齐
  输入 git config - -就会列出了一些參数
  三、git 简单配置
  1>.git最主要的配置
  通以上安装及配置git 输入命令自己主动完毕。还需最后一步就能够使用了
  git config —global user.name***
  ***设置成你自己的username
  git config —global user.email ***
  ***输入自己的email
  2>git配置的三个级别
  git config —system
  git config —global
  git config —local
  local 对当前仓库的,从优先来说,local最高,其次是global,由于他针对是当前的用户,最后是system
  查git config 文档 三种方式
  git config —help
  git help config
  man git-config
  3>git配置的增删改查
  1.上面的添加username,email一种,一个键后跟一个值
  2.用git config —global —add user.name rhc
  add 表明他有多个这种键值对
  能够依据这个键查询这个值 git config user.name
  也能够用git config —get user.name来查询
  通过以上两个命令查询,得出username是add 进去的rhc
  3.用git config —list —global能够查看所的有键值,发现user.name有两个
  仅仅是使用的是最后一个RHC
  hairongchen:git-master$ git config --list --global
  user.name=chenhairong
  user.email=baitxaps@126.com
  user.name=rhc
  4.删除
  hairongchen:git-master$ git config --global --unset user.name
  出现警告:
  warning: user.name has multiple values
  我们须要user.name后面加一个表达式如:git config --global --unset user.name rhc
  再查:
  hairongchen:git-master$ git config --list --global
  user.name=chenhairong
  user.email=baitxaps@126.com
  发现user.name 仅仅有一个值,仅仅有一个值时删除就不用加表达式了如:
  git config --global --unset user.name
  再查:git config --get user.name,就查不到了
  我们再添加回去:
  git config --global user.name rhc
  5.改动:
  git config --global user.email bawfnhaps@163.com,把曾经的email改了:
  hairongchen:git-master$ git config --list --global
  user.email=bawfnhaps@163.com
  user.name=rhc
  4>为git子命令配置别名
  给checkout 取别名co:git config --global alias.co checkout
  branch,status,commit配置别名例如以下:
  git config --global alias.br branch
  git config --global alias.st status
  git config --global alias.ci commit
  输入 git c 再按tab键出现,多了co,ci两个命令。我们以后可用ci来commit,co来checkout
  hairongchen:git-master$ git c
  c             cherry      citool      cm            commit
  ca            cherry-pick   clean         co            config
  checkout      ci            clone         column
  git 后面接參数
  输入命令发现:git log 发现后面输出了非常多内容
  使用以下命令:git config --global alias.lol"log —oneline"
  再用 git lol发现一行一行。非常整齐
页: [1]
查看完整版本: mac下的git的安装与简单的配置