Git常用指令
1 2
| $ git config --global user.name "Your Name" $ git config --global user.email "email@example.com"
|
$ pwd
$ git init
$ ls -ah
$ git add <file>
$ git commit -m <message>
$ git status
$ git diff <file>
$ git log
$ git log --pretty=oneline
$ git reflog
–hard会回退到上个版本的已提交状态,而–soft会回退到上个版本的未提交状态,–mixed会回退到上个版本已添加但未提交的状态.
$ git reset --hard HEAD~<num>
$ git reset --hard <version>
$ cat <file>
$ git checkout -- <file>
$ git reset HEAD <file>
$ git rm <file>
$ git remote add origin git@github.com:<yourname>/learngit.git
$ git push -u origin master
$ git push origin master
$ git remote -v
$ git remote rm <name>
$ git clone git@github.com:<name>/gitskills.git
$ git checkout -b <name>
$ git switch -c <name>
等同于
1 2
| $ git branch dev $ git checkout dev
|
或
1 2
| $ git branch dev $ git switch master
|
$ git branch
$ git merge <name>
$ git branch -d <name>
$ git branch -D <name>
$ git merge --no-ff -m "merge with no-ff" <name>
$ git stash
$ git stash list
恢复并删除
1 2
| $ git stash apply $ git stash drop
|
或
$ git stash pop
$ git cherry-pick <version>
$ git pull
$ git rebase
$ git tag <tag>
$ git tag <tag> <version>
还可以创建带有说明的标签,用-a指定标签名,-m指定说明文字:
$ git tag -a <tag> -m "info" <version>
$ git tag
$ git show <tag>
$ git tag -d <tag>
$ git push origin <tag>
$ git push origin --tags
先删除本地再:
$ git push origin :refs/tags/<tag>
补充

参考资料
廖雪峰