git安装和使用

安装依赖:
# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

 

卸载原版:
# yum remove git

 

解压安装:
# cd /usr/src
# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
# tar xzf git-2.9.5.tar.gz
# cd git-2.9.5
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install

# ln -s /usr/local/git/bin  /usr/local/bin

 

全局配置:
$ git config --global user.name "zmq"
$ git config --global user.email "zmq@zmq100.cn"

$ git config --global credential.helper store       .git-credentials
$ git config --system --unset credential.helper
$ git config --global http.emptyAuth true

 

.git-credentials

  http://user:password@ip


.gitconfig
  [user]
    name = zmq
    email = zmq@zmq100.cn
  [http]
    emptyAuth = true
  [credential]
    helper = storemanager

.minttyrc
  BoldAsFont=-1
  Language=zh_CN
  RightClickAction=paste


创建提交版本库:
$ git init                把目录变成repository版本库,生成.git目录(stage、master、HEAD)
$ git add file.txt          从工作区添加到暂存区(stage)
$ git commit -m "comment"       从暂存区(stage)一次性全部提交到当前分支(master)
$ git status            查看状态
$ git diff file.txt            查看修改内容

 

版本回退
$ git log              查看历史纪录
$ git log –pretty=oneline         简短查看历史纪录
$ git reflog               查看回退的版本号
$ git reset --hard HEAD^              回退到上一个版本^
$ git reset --hard HEAD~1           回退到上一个版本
$ git checkout -- file.txt                丢弃工作区的的修改/恢复(先回退到暂存区---没有在回到版本库)

 

远程仓库
$ git clone https://github.com/zmquan/test.git
$ git pull
$ git push origin master

 

总结创建与合并分支命令如下:
$ git branch                               查看分支
$ git branch name                     创建分支
$ git checkout name                 切换分支
$ git checkout –b name            创建+切换分支
$ git merge name                      合并某分支到当前分支
$ git branch –d name                删除分支

posted @ 2018-08-16 17:14  zmquan  阅读(113)  评论(0编辑  收藏  举报