git

git init
$ mkdir runoob
$ cd runoob/
$ git init
Initialized empty Git repository in /Users/tianqixin/www/runoob/.git/
$ ls -a
. .. .git
git配置
$ git config --list
credential.helper=osxkeychain
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
$ git config -e
$ git config -e --global
$ git config --global user.name "runoob"
$ git config --global user.email [email protected]
远程仓库
$ git remote add origin [email protected]:cicd/auto_sys.git
git remote -v
origin [email protected]:cicd/auto_sys.git (fetch)
origin [email protected]:cicd/auto_sys.git (push)
git remote rm [别名]
git commit
$ git add file
$ git add .
$ git commit -m "注释"
$ git commit -a -m "注释"
$ git log -n 1 --stat
git show commit-id
$ git commit --amend
分支操作
$ git checkout -b branch
$ git branch -m 旧名 新名
$ git checkout master;git checkout branch
$ git branch -a
$ git branch -vvv
git push --delete origin branch
$ git push --set-upstream origin branch
$ git push
$ git branch --set-upstream-to origin branch
$ git pull
合并分支
$ git checkout dev
$ git pull
$ git checkout master
$ git merge dev
$ git push -u origin master
二、当master代码改动了,需要更新开发分支(dev)上的代码
$ git checkout master
$ git pull
$ git checkout dev
$ git merge master
$ git push -u origin dev
git tag
$ git tag <tagName> //创建本地tag
$ git push origin <tagName> //推送到远程仓库
$ git push origin --tags
$ git log --pretty=oneline //查看当前分支的提交历史 里面包含 commit id
$ git tag -a <tagName> <commitId>
$ git show <tagName>
$ git tag 或者 git tag -l
$ git ls-remote --tags origin
$ git tag -d <tagName>
$ git push --delete origin <tagName>
commit 后的回滚操作
$ git reset --hard HEAD^
$ git reset HEAD XXX/XXX/XXX.java
$ git reset --soft commit~3,然后 git status
git diff
$ git diff
$ git diff --stat
$ git diff HEAD 或者 git diff cimmit-id
$ git diff --cached HEAD 或者git diff --cached commit-id
git diff commit-id commit-id
$ git diff HEAD^ HEAD
$ git diff test-1 master
运维干货分享