文章目录
0-git bash预配置
0.1-ssh
ssh-keygen -t rsa -C example@mail.com
cat ~/.ssh/id_ras.pub
- gitee分项目部署(clone、pull)和个人部署(pull+push)
0.2-git config
//基于仓库
git config
//基于用户,优先于基于仓库
git config --global
//基于系统
git config --system
1-创建仓库
2-remote add或clone
//关联或克隆能起到相同效果
//1-关联远程仓库
git init
git remote add origin http/git-path
git pull origin branch_name
//2-克隆仓库
git clone <-b branch_name> http/git-path newdocument
3-pull、push
- 本地推送分支:git push origin branch-name
- 推送分支前最好先pull分支:git pull origin branch-name
//设置默认提交remote-repository和branch
git push -u
//不同名分支推送
git push origin HEAD:remote_branch_name
git push origin local_branch_name:remote_branch_name
//直接push不同名会给远程仓库新建分支
4-reset
//状态、修改、日志
git status
get diff (file)
git log
//版本回退
git reset --hard HEAD^
HEAD到HEAD~100
git reset --hard 1094a
到commit id 为1094a的新提交
git通过head指针指向切换当前版本
//后悔药
git reflog
4.1-HEAD~和^
-
HEAD~num
//~2 向上两代;向上一代
-
HEAD^
//^ 向上一代;^^ 向上两代(等价~2)
-
HEAD^num
//^2 向上一代第二个parent节点;^^2 奶奶节点
-
组合使用
//~^2 奶奶节点
5-branch+checkout/switch
5.1-branch
- 查看分支信息:git branch -r
- 查看所有分支信息:git branch -a
//关联分支1
git branch --set-upstream-to=origin/remote_branch your_branch
//新建关联分支2
git checkout -b branch-name origin/branch-name
5.2-checkout/switch
//仅仅切换分支
git checkout branch_name
//-b新建并切换,加commit-hash复制本次commit到新分支
git checkout -b branch_name <hash>
//checkout文件,将add的文件移除暂存
git example.file
//switch
git switch branch_name
git switch -c branch_name <hash>
6-merge
//到主分支
git merge vice_branch
//pull/merge request