git init 初始化git
git clone 从远程仓库中克隆代码
git add 将更改的内容提交到暂存区(stage)
git commit 将暂存区的内容提交到当前分支
git diff 查看具体修改的内容
git status 查看当前仓库的状态(有没有文件被修改或添加新的文件)
git log 查看所有提交历史记录
git log --pretty=oneline 简化查看所有提交历史记录(一行显示)
git reflog 查看历史命令
git reset --hard HEAD^ 回到上一个版本(HEAD^^ 回到前两个版本,HEAD~100 回到前100个版本)
git checkout -- <fileName> 丢弃工作区对"fileName"文件的修改
git checkout . 丢弃工作区所有修改内容
git reset HEAD <fileName> 把暂存区的修改撤销掉(unstage),重新放回工作区
git branch 查看所有分支,当前分支前面会标一个*号
git branch <branchName> 创建一个叫"branchName"的分支
git checkout <branchName> 切换到"branchName"分支
git branch -d <branchName> 删除 "branchName" 分支(合并后的分支)
git branch -D <branchName> 删除一个没有合并过的分支"branchName"
git checkout -b <branchName> 创建并切换到 "branchName" 分支
git merge <branchName> 合并某个分支<branchName> 到当前分支(HEAD 应当先指向当前分支,再执行这个命令)
$ git merge --no-ff -m "commit description" <branchName>
合并分支时会生成一个新的commit,从分支历史上就可以看出分支信息
git log --graph 查看到提交的分支图 (为方便查看 可在其后加 --pretty=oneline)
git stash 将当前的工作区修改的文件存储起来,并清空工作区
git stash list 查看存储的文件
git stash apply 将stash恢复到工作区,但是恢复后stash不会删除(stash有多个时,后面可加上获取的list,删除特定的stash)
git stash drop 将存储的内容删除
git stash pop 将存储起来的东西恢复到工作区并删除
git remote -v 查看远程仓库的信息
git pull 从远程仓库中拉去代码
git push 将本地仓库的修改内容推送到远程仓库
git tag <tagName> 新建标签"tagName" (标签默认打在当前分支的最近一次提交上)
git tag 查看所有的标签
git tag <tagName> <commit id> 给历史提交的commit id打标签
git show <tagName> 查看某个tag的信息
git tag -a <tagName> -m <commit description> <commit id>
创建带有描述的标签 -a:标签名 -m:标签描述 id:某次提交
git tag -d <tagName> 删除某个标签
git push origin <tagName> 推送某个标签到远程仓库
git push origin --tags 推送所有的标签到远程仓库
git push origin :refs/tags/<tagName> 删除远程仓库的某个标签(前提是先删除对应本地的标签)
具体学习可看这里:
@廖雪峰:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
@阮一峰:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html