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

python类中方法返回自身值类型的写法

在python3中使用类型遇到的问题,代码如下:

想在factory创建自已,以为类型是这样的-> People

1
2
3
4
5
6
7
8
9
class People:
name: str

def __init__(self, name: str) -> None:
self.name = name

@classmethod
def factory(cls, name: str) -> People:
return cls(name)

这样的错的

正确的写法是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
from typing import TypeVar, Type

T = TypeVar('T', bound='People')

class People:
name: str

def __init__(self, name: str) -> None:
self.name = name

@classmethod
def factory(cls: Type[T], name: str) -> T:
return cls(name)

要写成泛型才对,问题地址:https://github.com/python/peps/pull/89

另一种方法

类型写成字符串也是可以的

1
2
3
4
5
6
7
8
9
class People:
name: str

def __init__(self, name: str) -> None:
self.name = name

@classmethod
def factory(cls, name: str) -> "People":
return cls(name)

pip安装模块出现neither-setup.py-nor-pyproject.toml-found

使用pip安装模块时出现neither 'setup.py' nor 'pyproject.toml' found.导致模块无法安装

因为根据打包方案,项目中需要一个setup.py或pyproject.toml用于生成包的配置文件,然而模块里没有按照这个规定来

网上搜了一遍,没找到解决方案

只能选择手动安装

https://pypi.org/,找到相应的包,下载下来解压到python的Lib目录

windows下缺失fcntl报错

windows下运行python项目,报错ModuleNotFoundError: No module named 'fcntl'

fcntl库是linix的Python发行版才有,windows没有带

方法一

pip安装缺失的包,这个地址去搜索https://libraries.io/search?q=micropython

1
pip install micropython-xxx

仓库地址:https://github.com/micropython/micropython

方法二

在python库文件目录D:\Python\Python38\Lib\site-packages中创建’fcnty文件,内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def fcntl(fd, op, arg=0):
return 0

def ioctl(fd, op, arg=0, mutable_flag=True):
if mutable_flag:
return 0
else:
return ""

def flock(fd, op):
return

def lockf(fd, operation, length=0, start=0, whence=0):
return

maven项目添加第三方jar库

第三方的sdk没在maven公共仓库里,需要下载jar集成到maven项目里

把jar文件拷贝到项目里

在根目录或resources创建lib目录,把jar文件拷贝进去

修改pom.xml文件,添加依赖

1
2
3
4
5
6
7
8

<dependency>
<groupId>com.example</groupId>
<artifactId>opensdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${pom.basedir}/src/main/resources/lib/opensdk.jar</systemPath>
</dependency>

修改spring-boot-maven-plugin

1
2
3
4
5
6
7
8
9
10
11
12

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>

刷新maven或者重新打开项目

mysql创建只读用户

创建只读用户

1
2
3
4
# 格式
GRANT SELECT ON dbName.tableName TO 'username'@'host' IDENTIFIED BY "password";
# 刷新权限
FLUSH PRIVILEGES;

例子,用户readonly_user可以在当前mysql的服务器,只读方式访问所有数据库

1
2
GRANT SELECT ON *.* TO 'readonly_user'@'localhost' IDENTIFIED BY "12345678";
FLUSH PRIVILEGES;

分步创建

1
2
3
CREATE USER 'readonly_user'@'%' IDENTIFIED BY '12345678';
GRANT SELECT ON *.* TO 'readonly_user'@'%';
FLUSH PRIVILEGES;