Skip to content

Instantly share code, notes, and snippets.

@zhangskills
Created September 25, 2014 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangskills/feebc4fd9394b39bfcdc to your computer and use it in GitHub Desktop.
Save zhangskills/feebc4fd9394b39bfcdc to your computer and use it in GitHub Desktop.
git相关
@zhangskills
Copy link
Author

一不小心把本地的临时分支push到server上去了,想要删除。
一开始用

git branch -r -d origin/branch-name

不成功,发现只是删除的本地对该远程分支的track,正确的方法应该是这样:

git push origin :branch-name

冒号前面的空格不能少,原理是把一个空分支push到server上,相当于删除该分支。

@zhangskills
Copy link
Author

有时候需要删除版本库历史上的文件,比如想删除之前版本库中MyEclipse项目配置文件,只需在.git目录下执行:

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch .settings/*" --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch .project" --prune-empty --tag-name-filter cat -- --all

@zhangskills
Copy link
Author

git log统计功能

仓库提交者排名前 5(如果看全部,去掉 head 管道即可):

git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5

仓库提交者(邮箱)排名前 5: 这个统计可能不会太准,因为很多人有不同的邮箱,但会使用相同的名字.

git log --pretty=format:%ae | gawk -- '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }' | sort -u -n -r | head -n 5

贡献者统计:

git log --pretty='%aN' | sort -u | wc -l

提交数统计:

git log --oneline | wc -l

添加或修改的代码行数:

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/;'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment