Git:LF will be replaced by CRLF、pytest PermissionError以及Git应用中的一些问题解决及一些使用技巧

发布于:2024-10-17 ⋅ 阅读:(5) ⋅ 点赞:(0)

一、Git:LF will be replaced by CRLF和pytest: --cov NTERNALERROR PermissionError

1. git warning: LF will be replaced by CRLF in ***file

    偶然git add在进行代码提交的时候碰到警告warning: LF will be replaced by CRLF in ***file,原因是编辑的代码内容中存在符号转义问题,windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时,git发现改动文件中引入了LF会发出警告你哪些文件不是纯CRLF文件,但git不会自动修改工作区的文件,而是对暂存区进行修改。我们也可不做任何处理,它只是会提示,对代码提交无影响。

$ git add .
warning: LF will be replaced by CRLF in ***file
The file will have its original line endings in your working directory
#可使用如下解决办法如下:
$ git config --global core.autocrlf false

    core.autocrlf:Setting this variable to "true" is almost the same as setting the text attribute to "auto" on all files except that text files are not guaranteed to be normalized: files that contain CRLF in the repository will not be touched. Use this setting if you want to have CRLF line endings in your working directory even though the repository does not have normalized line endings. This variable can be set to input, in which case no output conversion is performed.

2. pytest --cov NTERNALERROR> PermissionError:另一个程序正在使用此文件

    在进行pytest自动化测试的时候,发现使用pytest执行命令正常,但是使用pytest --cov度量测试覆盖率时会报错:INTERNALERROR> PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'F:\.coverage5.17332.110161' 。从报的错误来看是提示pytest生成的临时文件.coverage..被其它程序占用,但我本地确实没有进行其它的操作,后来想了想也许和打开的代码IDE软件有关,里面会列出了工作目录中的文件,包括临时生成的.coverage文件,于是关闭IDE软件发现运行正常。但依然感觉有点问题,因为之前我在同样的情况下也是正常的,不过有一种可能就是和我电脑上安装了公司的加密软件有关系吧。
    针对这种情况,也不用怎么去解决,在进行pytest测试代码编写的时候不用去度量生成覆盖数据,即只进行pytest命令即可,待测试脚本全部写好再进行覆盖率测算,这时也就不需要打开pytestIDE了。

3.shell中获取软链接指向的target目标路径

    在进行jenkins发布的时候,通过切换软链接来变更线上的代码版本,于是偶尔会有需求获取当前的current指向的版本(用来回滚)这时就需要在shell中获取软链接指向的target目标路径了,有什么好的办法呢?本来我是想找找有没有这种命令,比如我的软链名是current.如果能使用ln -showtarget current这种命令直接操作得到就好了,不过没有找到。业务中又需要,到也不是不能实现,只是觉得有更直接好用的命令方法吧,使用shell获取软链接指向的target目标路径可以使用grep或者find来操作,示例如下:

#第1种可以通过grep匹配当前的项中存在软链接的关键词来实现
root@test:/tmp/testdir# ls -al /tmp/testdir |grep -o '/tmp/testdir.*'
#第2种通过find实现
root@test:/tmp/testdir# find -type l -ls | grep current | awk '{print $13}'

 

二、Git应用中的一些问题解决及一些使用技巧

1. git diff 文件比对时中文编码问题。

    git diff 一个有差异的文件时,如果出现中文差异,显示出的内容无法阅读,如下内容所示。这时可以通过修改git config配置几个命令来解决。
+ //<E4><BF><9D><E5><AD><98>

#在命令行下输入以下命令:
$ git config --global core.quotepath false          # 显示 status 编码
$ git config --global gui.encoding utf-8            # 图形界面编码
$ git config --global i18n.commit.encoding utf-8    # 提交信息编码
$ git config --global i18n.logoutputencoding utf-8  # 输出 log 编码
$ export LESSCHARSET=utf-8

2. 在本地创建项目并和刚创建的git项目同步的步骤

A.在项目根目录执行git init命令创建本地项目,
B.在git服务器上创建一个仓库。
C.执行git remote add origin <git path>,git_path
D.从远程分支拉取master分支并与本地master分支合并。git pull origin master:master
E.提交本地分支到远程分支:git push -u origin master

3.Git可以支持多个远程服务端,并能从其中一个读取再写入另一个。

#添加一个远程服务端
$ git remote add john git@github.com:test/test.git
#查看远程服务端
$ git remote -v 
origin  http://1.git (fetch)
origin  http://1.git (push)
$ git remote show
$ git remote show origin 
$ git log #查看更新记录

4.merge和rebase合并分支

以后你可能想合并你的变动,有两种方式可以做到这一点:
$ git checkout master
$ git merge feature83 # Or...
$ git rebase feature83

    merge和rebase的区别是,merge会尝试解决改动并创建的新的提交来融合他们。rebase则是将从你最后一次从另一个分支分离之后的改动并入,并直接沿用另一个分支的head指针。尽管如此,在你往远端服务器上推送分支之前,不要使用rebase。这会让你混乱。如果你不能确定哪个分支(哪些需要合并,哪些需要移除)。这里有两个git分支切换方式来帮助你:

# Shows branches that are all merged in to your current branch
$ git branch --merged
# Shows branches that are not merged in to your current branch
$ git branch --no-merged

5. git log的使用。

    git log可以列出历史的提交列表,如果想快速查看最近的变动内容,可以使用git log -p。这个p估计就是present的意思吧。而如果只需要看最近文件变动的摘要,可使用$ git log --stat。其它还可以通过log内容来搜索:
$ git log --author=kermit #根据指定的作者查找:
$ git log --grep="keyword" #搜索你提交信息的内容
$ git log --since=2.months.ago --until=1.day.ago #使用ActiveSupport风格的日期来缩短时间范围
$ git count-objects -v #查看数据库使用的统计


网站公告

今日签到

点亮在社区的每一天
去签到