告诉git你是谁
git config --global user.name name
git config --global user.email email
生成公钥
ssh-kengen -t rsa -C pujing@whichcompany.cn
-t 默认 rsa
-C 注释
生成
xx // identification xx.pub // public key
branch
- git branch [branchname] //创建分支
- git branch //查看分支
- git branch -a //查看所有分支,包含远程
- git branch -a | grep feature // 查找相关名称的分支
git branch new-branch
switch branches
- git checkout [branchname] //切换分支
git checkout -b branchname
// 创建并切换分支git push --set-upstream origin branchname
// 创建的本地分支推到远程git checkout -b localBranchName remoteBranchname
merge branches
git merge branchname
把分支合并到当前分支
分支合并到master
git checkout master
git merge branchname
git merge --no-ff // 始终创建一个合并节点
git merge --squash // 创建一个合并节点,且历史提交节点合并成一个记录
git merge --fast-forward // 无合并节点
tag新增/删除
git tag <tagName>
git push origin <tagName>
git tag --delete <tagName>
git push origin --delete tag <tagName>
注:sourceTree看不出本地/远程tag,得都删掉
remote
git remote -v
git add origin xxxx
git rename origin xxx
delete
git branch --delete localBranch
git push origin --delete remoteBranch
cherry-pick
git cherry-pick hashNode
git cherry-pick node..node // 前开后闭区间
git cherry-pick node^..node // 前闭后闭区间
重置
git reset --hard <hashNode>
git push -f
安全保障
回到某个节点的操作
git reflog
配置文件
~/.git_config
- 配置别名 [alias] xx = xxx
别名
gl ga gba gbr
事故处理
- branch/tag-filter // 持续合并入publish,且分支已删
- branch/optimize-filter // 中间阶段误合并入publish
处理过程:
// 假设错误合并前节点为 88888888
// check一个新分支出来操作更清爽, 再pick错误合并后提交的内容
$publish: git checkout -b branch-cp 88888888
$branch-cp: git cherry-pick xxxx..xxxx
$branch-cp: gco publish
$publish: git reset --hard 88888888
$publish: git push -f
$publish: git merge branch-cp