简介
- 在看了廖雪峰老师的课后,做了一些笔记,本文是对操作的归纳。
操作
初始化
添加文件
1 2
| git add <file> git commit -m <message>
|
查看状态
版本回退
1 2 3 4 5 6
| git reset --hard commit_id git log git reflog git checkout -- file git reset HEAD <file> git rm
|
SSH Key
1
| ssh-keygen -t rsa -C "youremail@example.com"
|
在用户主目录里找到.ssh文件,把当中的id_rsa.pub内容放到GitHub里面。
远程库
1 2 3 4
| git remote add origin git@server-name:path/repo-name.git git push -u origin master git push origin master git clone git@server-name:path/repo-name.git
|
分支
1 2 3 4 5 6 7 8 9 10 11
| git branch git branch <name> git checkout <name> git switch <name> git checkout -b <name> git switch -c <name> git merge <name> git branch -d <name> git log --graph --pretty=oneline --abbrev-commit git merge --no-ff -m"<message>" <name> git branch -D <name>
|
保存现场
1 2 3
| git stash git stash pop git cherry-pick <commit>
|
多人工作
1 2 3 4
| git push origin <branch-name> git pull git branch --set-upstream-to <branch-name> origin git rebase
|
标签
1 2 3 4 5 6
| git tag -a <tagname> -m"<message>" git tag git push origin <tagname> git push origin --tags git tag -d <tagname> git push origin :refs/tags/<tagname>
|