1、git安装的配置
git config --global user.name "your name"
git config --global user.email "your email"
2、初始化git仓库
git init
3、添加文件到git仓库
git add file1 //添加file1
git . //添加当前目录所有文件
git commit -m "add file1" //-m 后面接的是提交代码的备注
4、查看仓库当前状态
git status
5、查看某个修改的内容
git diff <file>
6、版本切换
git reset --hard HEAD^ //回退到上个版本
git reset --hard commit_id //切换到某个特定的版本
git reflog //查看历史命令
7、撤销修改
git checkout -- <file> //撤销工作区的修改
git reset HEAD <file> //将暂存区的修改退回到工作区
8、删除文件
git rm <file>
git commit -m "remove file"
git branch //查看分支
git branch <branch_name> //创建分支
git checkout <branch_name> //切换分支
git merge <branch_name> //合并某分支到当前分支
git branch -d <branch_name> //删除分支
git merge --no-ff -m "merge" <branch_name> //这样合并分支时不会丢掉分支信息
10、存储工作现场
git stash //存储工作现场
git stash pop //恢复工作现场
git pull //合并更新
git push origin <branch_name> //推送修改到远程库