git一些操作分享

203 阅读1分钟

给.gitignore添加文件

直接添加规则,类似这种,是无效的

logs/*.log\
logs/\
/logs/

正确方法,先清除一下相关的缓存,让所有的文件变成未追踪的状态:

git rm -r --cached . 
git add . 
git commit -m 'update .gitignore'

强制覆盖远程master

在开发中,通常会保持两个分支master分支和develop分支,但是如果因为develop上面迭代太多而没有及时维护master,最后想丢弃master而直接将测试确认过的develop强推到master

git push origin develop:master -f // 把本地的develop强制推送到远程master
git checkout master
git fetch --all // 下载远程最新内容,不合并
git reset --hard origin/master // 更改HEAD指向

git提交跳过检查

git commit --no-verify -m "修改..."

.gitattributes 文件,统一mac windows

# 确保所有文本文件都用 LF(避免 Windows 自动换 CRLF)
* text=auto eol=lf

# 针对 Husky 脚本:强制保持可执行权限
.husky/* text eol=lf
.husky/* -text