本文源于一年前(2015年7月)的Git学习笔记,主要是常用命令的总结,参考自廖雪峰的官方网站。
最常用命令: clone, add, commit, push
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| git clone https://github.com/buguake/cms.git
git add .
git commit -m "<your comment of this commit>"
git commit -a -m "blabla..."
git push origin master
git reset <commit>
git commit --amend
|
非常有用的命令
1 2 3 4 5 6 7 8 9 10
| git branch --set-upstream-to branch-name origin/branch-name
git rm -r --cache .
git remote add origin https://github.com/xjiajiahao/learngit.git
git clone --depth=1 https://github.com/xjiajiahao/BPlusTree ~/BPlusTree
git checkout dev
|
基本命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| git config --global user.name "Your Name" git config --global user.email "email@example.com"
mkdir learngit cd learngit
pwd
git init
git add readme.txt
git commit -m "wrote a readme file"
git status
git diff readme.txt
git log git log --pretty=oneline
git log --pretty=oneline --abbrev-commit
git reset --hard HEAD^ git reset --hard 3628164 gitreflog
cat readme.txt cat > readme.txt cat file1 file2 > file
git diff HEAD -- readme.txt
git checkout -- readme.txt
git reset HEAD readme.txt
git rm test.txt git commit -m "remove test.txt"
git checkout -- test.txt
|
远程仓库
1 2 3 4 5 6 7 8 9 10 11 12
| ssh-keygen -t rsa -C"youremail@example.com"
git remote add origin https://github.com/xjiajiahao/learngit.git git push -u origin master git push origin master
git clone git@github.com:xjiajiahao/gitskills.git git checkout -b dev origin/dev
|
分支(Branch)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| git checkout -b dev
git branch dev git checkout dev
git branch
git merge dev
git branch -d dev
git log --graph --pretty=oneline --abbrev-commit
git merge --no-ff -m "merge with no-ff" dev
git stash
git stash list
git stash pop git stash apply git stash apply stash@{0} git stash drop
git branch -D feature-vulcan
|
多人协作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| git remote git remote -v
git push origin master
git checkout -b dev origin/dev
git pull
git branch --set-upstream branch-name origin/branch-name
|
其他
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| git tag v1.0
git tag v0.96224937
git tag
git show <tagmame>
git tag -a v0.1 -m "version 0.1 released"3628164
git tag -s v0.2 -m "signed version 0.2 released" fec145a
git tag -d v0.1
git push origin v1.0
git push origin --tags
git push origin :refs/tags/v0.9
git config --global alias.st status git config --global alias.co checkout git config --global alias.ci commit git config --global alias.br branch
git config --global alias.unstage 'reset HEAD'
git config --global alias.last 'log -1'
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|