Git记录

128 阅读1分钟

1.查看远程仓库的分支:git branch -r
2.查看本地和远程仓库的所有分支:git branch -a image.png
查看本地分支: git branch
3.同步远程分支

image.png
当我直接本地切换分支develop,运行git checkout -b develop, 是不成功的
4.修改分支名称

1.本地分支重命名(未推送到远程) 
git branch -m oldName newName  
2. 删除远程分支  
git push --delete origin oldName  
3.上传新命名的本地分支 
 git push origin newName  
4.将修改后的本地分支关联远程分支  
git branch --set-upstream-to origin/newName  

5.远程新建分支,本地获取不到

git remote  列出所有远程主机  
git remote update origin --prune  更新远程主机origin整理分支  
git branch -r   列出远程分支  
git branch -vv   查看本地分支与远程分支对应关系  
git checkout -b aaa origin/aaa   新建本地分支aaa并与远程分支aaa关联  

6.本地新建分支并推至远程(branch 本地和远程都没有) git checkout -b branch git push --set-upstream origin branch
7.代码统计:

1.统计个人代码量:  
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 }' -  
2.查看排名前五贡献者:  
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5  
3.使用cloc  
 首先,全局安装
npm install -g cloc  
然后,进入项目,执行:
cloc . 即可。