基本操作
git init //初始化命令
git add //添加到暂存区 工作区→暂存区
git commit // 提交到版本库 暂存区→版本区
git commit --allow-empty 允许空commit,打开文件型提交
git log //查看log
git status//查看状态
回滚
git reset --hard [commit ID] //版本区-回滚->commit ID
git reset HEAD file_name //暂存区的内容-回滚->工作区状态
git reflog //查看回滚前的log
git reset --soft [commit ID] //软回滚,commit信息回滚,但代码依然在
分支
git branch 查看分支
git branch branch_name//当前枝条下创建分支
git checkut branch_name//切换分支
git merge other_branch//其他分支合并到当前分支
(可能会产生冲突)
git branch -d branch_name //删除分支
gitHub仓库
1.注册
2.建立仓库
3.推送
git remote add origin web_adr //仓库别名
git clone web_adr//克隆仓库中的代码
git push (-u 设置默认用) origin branch_name //推送到网站仓库
git pull origin branch_name//从网站仓库中拉下分支
git pull origin branch_name = git fetch origin branch_name + git merge origin branch_name
★git rebase//目的:使git提交记录变得简洁
应用场景
git rebase -i HEAD~3
git log --graph//以流程图片的方式显示提交日记
git log --graph --pretty=format:"%h %s"
解决冲突
借助git自带的软件即可解决冲突