git init
git add .
git commit -m "注释"
git remote add origin [远程仓库地址]
git push -u origin master //客户端首次提交
2. 分支命令
git branch [branch-name] //构建分支
git checkout [branch-name] //切换分支
git branch -r //查看远程分支
git branch //查看本地分支
git branch -a //查看本地(标*为本地)和远程分支
git push origin [branch-name] //将本地分支推送到远端
git branch -d [branch-name] //删除本地分支
git branch origin :[branch-name] //删除远程分支
git merge [branch-name] //合并分支到主干
git push origin[local-branch]:[remote-branch] //提交分支
3. 拉取和提交
git pull //抓取远程仓库所有分支更新并合并到本地
git fetch origin //抓取远程仓库更新
git push //提交所有分支
4. 查看命令
git help <command> //查看命令帮助
git show //显示某次提交的内容 git show id
git log git log <file> //查看该文件每次提价记录
git log -p <file> //查看每次详细修改内容的diff
git log --stat //查看提交统计信息(详细)
git log //查看提交记录(简略)
git diff <branch1>..<branch2> //在两个分支之间比较
git diff <id1> <id2> //比较两次提交之间的差异
5. 删除、恢复
git co --<file> //抛弃工作区某个文件的修改
git co //抛弃工作区所有的修改
git add <file> //将工作文件提交到本地暂存区
git add . //将所有修改过的工作文件提交暂存区
git rm <file> //从版本库中删除文件
git rm <file> --cached //从版本库中删除文件,但不删除文件
git ci --amend //修改最后一次提交记录
git reset HEAD //恢复所有内容到上一个版本
git reset <file> //恢复该文件到上一个版本
git reset --hard origin/[branch-name] //将本地的状态恢复到和远程一样
git reset <$id> //恢复到某个版本
git reset --soft //回退到某个版本,只回退了commit的信息,不会恢复到index file一级
git reset --hard [$id] //彻底回退到某个版本,本地的源码也会变成上一个版本的内容
git revert <$id> //恢复到某个版本
git revert HEAD //恢复最后一次提交的状态
git revert 是生成一个新的提交来撤销某次提交,此次提交之前的commit都会被保留
git reset 是回到某次提交,提交及之前的commit都会被保留,但是此次之后的修改都会被退回到暂存区