git统计提交记录中修改过的文件

使用git的log命令

1
2
3
# start_commit_id 起始提交ID
# end_commit_id 结束提交ID
git log --author=abc --name-only --pretty= start_commit_id..end_commit_id

只显示文件pretty必须为空

1
2
# 显示commit_id和文件
git log --author=abc --name-only --pretty=oneline start_commit_id..end_commit_id

git错误invalid path解决方法

在windows上git clone代码时报错:error: invalid path ‘xxxx’

解决方法:

1
git config core.protectNTFS false

参数说明:

1
2
core.protectNTFS
If set to true, do not allow checkout of paths that would cause problems with the NTFS filesystem, e.g. conflict with 8.3 "short" names. Defaults to true on Windows, and false elsewhere.

git文件名过长错误解决方法

git使用过程中,出现error: unable to create file xxx: Filename too long Updated 0 paths from the index

原因是windows的git版本中如果是文件名太长了,git会报错

解决方法:

1
2
3
4
5
# 选其一
# 全局设置
git config --global core.longpaths true
# 当前项目设置
git config core.longpaths true

对git仓库进行清理

git仓库使用很长一段时间后,因为提交次数多了.git目录会越来越大;导致构建检出tag时耗时特别长。

整理了清理git仓库方法

使用bfg工具清理

下载地址:https://github.com/rtyley/bfg-repo-cleaner

使用步骤:

下载bfg,是一个jar文件,需求安装java环境才能执行

清理命令

1
2
# 清理>10M的文件
java -jar bfg-path/bfg.jar --strip-blobs-bigger-than 10M --no-blob-protection your-git-repo-path

进入仓库目录,执行

1
2
cd your-git-repo-path
git reflog expire --expire=now --all && git gc --prune=now --aggressive

漫长的等待过后,推送到远程

1
git push --force

自已的项目可以像这样搞,如果是多人使用的仓库,最好是清理后迁移成一个新仓库,然后所有人重新clone

git遇到pull出现403问题

git拉代码失败,不提示输入账号密码,出现The requested URL returned error: 403

解决方法,清除密码缓存

1
2
3
git config --local --unset credential.helper
git config --global --unset credential.helper
git config --system --unset credential.helper

之后就可以重新输入账号密码拉代码了

github多帐号添加ssh公钥

github有两个账号,但是同一个ssh公钥只能添加给一个账号,需要再生成一个密匙后添加。步骤如下:

再添加一个ssh密匙

1、指定邮箱

1
2
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.

2、提示输入生成位置和文件名,取个不同的名称。如: /Users/you/.ssh/id_rsa1

1
Enter file in swhich to save the key (/Users/you/.ssh/id_rsa):