安装
$
git 查看
$
sudo apt-get install git 安装
$
sudo apt-get install git-core 安装(老版本系统)
$ git config --global user.name "Your Name" 设置用户名
$
git config --global user.email "email@example.com" 设置email地址
==========
==========
==========
==========
==========
创建库
$ mkdir mygit
$ cd
mygit
$ pwd
$ git init
==========
==========
==========
==========
==========
添加文件到库
$ git add mytestgit.txt 添加
$ git commit -m "new file" 提交
==========
==========
==========
==========
==========
查看库
$ git status 查看库状态
$ git diff
mytestgit.txt
$ git log
$ git log --pretty=oneline
$ cat
mytestgit.txt
==========
==========
==========
==========
==========
版本退回
$ git reset --hard HEAD^
$ git reset --hard xxx (xxx是文件版本号)
$ git reset HEAD readme.txt
$ git reflog
$ git checkout --
mytestgit.txt
撤销修改
$ git rm
mytestgit.txt
删除文件
==========
==========
==========
==========
==========
远程库
$ ssh-keygen -t rsa -C "
email@example.com
"
$ git remote add origin git@github.com:username/mytestgit.git
$ git remote add origin http://xxx.xxx.xxx.xxx/mytestgit.git
$ git push origin master
$ git clone
git@github.com:username/mytestgit.git
$ git clone
http://xxx.xxx.xxx.xxx/mytestgit.git
$ git remote 查看远程库信息
$ git remote -v 查看远程库详细信息
$ git pull
$
git checkout -b branch-name origin/branch-name
$ git branch
==========
==========
==========
==========
==========
分支
$ git branch aaa 创建分支
$ git checkout aaa 切换分支
$ git checkout -b aaa 创建并切换分支
$ git branch 查看分支
$ git merge dev 合并分支
$ git branch -d aaa 删除分支
$ git log --graph --pretty=oneline --abbrev-commit 查看分支合并
$ git merge --no-ff -m "merge bbb --no--ff" bbb 历史模式合并
$ git stash 存储分支
$ git stash list 查看存储分支
$
git stash apply 恢复存储分支
$
git stash drop 删除存储分支
$ git stash pop 恢复并删除存储分支
$ git branch -D ccc 强行删除未合并分支
==========
==========
==========
==========
==========
标签
$ git tag v1.0 新建标签
$ git tag 查看标签
$ git tag v1.1 xxxxx
$
git tag -a v1.2 -m "v1.2" xxxxxx
$ git show v1.1
$
git tag -d v1.1 删除标签
$ git push origin v1.2
$ git push origin --tags 推送标签
$
git push origin :refs/tags/<tagname> 删除远程标签