工作区–>暂存区–>仓库区–>服务器
(1)设置用户签名
git config --global user.name 用户名
git config --global user.email 邮箱
cat ~/.gitconfig
[user]
name = Layne
email = Layne@atguigu.com
(2)初始化本地库
git init
(3)查看本地库状态
git status
(4)新增文件
vim hello.txt
(5)添加到暂存区
git add hello.txt
(6)提交到本地库
git commit -m "提交hello.txt文件" hello.txt
(7)查看历史版本
git reflog 查看版本信息
git log 查看版本详细信息
(8)版本回退或穿梭
git reset --hard 版本号
(9)查看一个分支的最后一次提交
git branch -v
(10)查看所有分支列表(包括本地和远程,remotes/开头的表示远程分支)
git branch -a
(11)创建分支
git branch 分支名
(12)切换分支
git checkout 分支名
(13)合并分支
git merge 分支名
1)在master主分支上合并hot-fix分支
1.切换到master分支上,git checkout master
2.在master主分支上,进行合并,git merge hot-fix
1)在hot-fix分支上合并master分支
1.切换到hot-fix分支上,git checkout hot-fix
2.在hot-fix分支上,进行合并,git merge master
(14)冲突解决
1).合并如果发生了冲突,手动解决冲突
2).冲突解决了之后,重新提交
1.git add hello.txt
2.git commit -m "hello.txt文件冲突解决了" (git commit 命令时不能带文件名)
(15)远程仓库操作
1)查看当前所有远程地址别名
git remote -v
2)起别名
git remote add 别名 远程地址
3)推送本地分支上的内容到远程仓库
git push 别名 分支
4)将远程仓库的内容克隆到本地
git clone 远程地址
5)将远程仓库对于分支最新内容拉下来后与当前本地分支直接合并
git pull 远程库地址别名 远程分支名