[关闭]
@zifehng 2018-04-07T04:11:56.000000Z 字数 1303 阅读 1029

git使用简要笔记

git


1. 升级最新版本git

ubuntu默认下载源中git不是最新版本,执行以下操作以升级到最新版git

  1. $ sudo add-apt-repository ppa:git-core/ppa
  2. $ sudo apt-get update
  3. $ sudo apt-get upgrade

2. 使用ssh协议连接github

  1. $ ssh-keygen

生成的公钥文件为: ~/.ssh/id_rsa.pub

  1. $ git clone git@github.com:zifehng/MarkDownPhotos.git

3. 使用git前的一些配置

  1. $ git config --global user.name "wangshusheng"
  2. $ git config --global user.email "wangshusheng2016@foxmail.com"
  1. $ git config --global color.ui true
  1. $ git config --global core.editor "vim"
  1. $ git config --global core.excludesfile ~/.gitignore_global

4. 常用操作

4.1 回退版本

  1. $ git reset --hard HEAD^
  1. $ git reset --soft HEAD^
  1. $ git reflog

4.2 撤销修改

  1. $ git checkout --test.c
  1. $ git reset HEAD test.c

4.3 查看提交历史

  1. $ git log --stat
  1. $ git log -3
  1. $ git log -p

4.4 分支操作

  1. $ git branch
  1. $ git branch test
  1. $ git branch -m test newtest
  1. $ git checkout test
  1. $ git checkout -b test
  1. $ git merge test
  1. $ git branch -d test

4.5 暂存改动

  1. $ git stash
  1. $ git stash pop
  1. $ git stash list
  1. $ git stash pop stash{3}

4.6 远程协作

  1. $ git remote add origin 192.168.1.101:sample.git
  1. $ git branch -r
  1. $ git fetch
  1. $ git checkout -b local_test origin/test
  1. $ git pull origin test:local_test
  1. $ git push origin local_test:test
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注