Git是什么?
Git是目前世界上最先进的分布式版本控制系统。
【git教程】
Git命令要多加练习 在线练习网站
一般流程
- git clone 一个仓库或子仓库(git/http(s))建议采用ssh(使用git协议) 配置多个SSH的key 建议参考多【ssh的配置】
- git checkout -b xxx origin/master 基于master分支新建分支 todo Something in workspace(工作区)
git add . 添加到Index(暂存区) git commit -m ‘msg’添加到Repository(本地仓库) git push origin xxx 推送本地仓库到Remote(远程仓库)
commit msg 规范可以参考 多分支管理合并策略 参考
这样远程就有一个xxx的分支 可以配合多分支管理策略 管理部署和发布
Git别名设置
建议如下配置 参考【廖雪峰-git别名配置】
git config --global alias.st status
git config --global alias.co
git config --global alias.br branch
git config --global alias.last 'log -1'
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Git基本操作
常用的git命令
git add .
git add *
git add src/*
添加到index中git commit
提交到本地仓库中git push origin master
推送到远程仓库中git push origin dev
推送到远程仓库 dev分支中git 解决冲突
下载冲突到缓存区 git pull不安全
- git fetch 远程到 本地仓库
-
git 合并分支
git checkout xxx 切换到 xxx分支上
git merge —no-ff develop 合并分支到develop上 —no-ff 快速合并
创建分支
git checkout -b feature-x develop
基于develop分支创建feature-x 分支 开发完成后,将功能分支合并到develop分支: *git checkout develop
切换分支git merge --no-ff feature-x
合并分支 删除feature分支:git branch -d feature-x
删除分支
查找head 手动 合并 代码
开始
- git add add文件
- git commit 添加
- git pull 更新
- git push 提交
处理流程 小乌龟
- commit
- fetch
- rebase
git log统计
统计代码量可以采用cloc
统计个人代码量
git log --author="jartto" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
贡献值统计
git log --pretty='%aN' | sort -u | wc -l
3 .查看排名前 5 的贡献者
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5
git cherry-pick
git cherry-pick
命令的作用,就是将指定的提交(commit)应用于其他分支。
具体参看阮大师的
git cherry-pick hashA hashB
git cherry-pick <HashA> <HashB>
git 拾取 包含A 。。B的hash
git cherry-pick A^..B