Git和Github踩坑记
Git
git提交或克隆报错fatal: unable to access#
解决方式见git提交或克隆报错fatal: unable to access_HZC8的博客-CSDN博客_unable to access git
问题#
git在拉取或者提交项目时,中间会有git的http和https代理,但是我们本地环境本身就有SSL协议了,所以取消git的https代理即可,不行再取消http的代理。
解决办法#
在项目文件夹的命令行窗口执行下面代码,取消git本身的https代理,使用自己本机的代理。
git config --global --unset http.proxy//取消http代理
git config --global --unset https.proxy//取消https代理
{% btn 'https://img.shields.io/badge/2023%2F01%2F10-新增-blue',2023/01/10 新增,,blue %}如果还是不行,可以把网络的DNS配置改为 114.114.114.114 即可正常访问。
git提交报错OpenSSL SSL_read: Connection was reset, errno 10054#
问题#
开了VPN老是报各种离谱错误。
解决方法#
git config --global http.sslVerify false #修改设置,解除ssl验证
Failed to connect to github.com port 443 after 2289 ms: Connection refused#
问题#
如题,在终端执行git clone时提示Failed to connect to github.com port 443:Connection regused错误
解决方案#
本地有连接vpn,通过在终端输入以下命令解决:
git config --global http.proxy http://127.0.0.1:7897
说明:7897为本地混合配置的端口号
.gitignore不生效#
原因#
原因是 .gitignore 只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
简单来说就是,你新添加的忽略项已经被git追踪了。
解决方案#
那么解决方法就是先把本地缓存删除(改变成未track状态),然后再提交。
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
参考资料#
fatal: unable to access 'xxx.git/': Recv failure: Connection was reset#
解决方案#
不知道原因,但是更新一下origin
就好了。
git remote set-url origin https://github.com/xxx/xxxx.git
参考资料#
pre-commit/hook: No such file or directory#
问题#
如题,执行git push
时出现这个问题
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
原因是当你试图git commit
的时候,pre-commit hook
最先执行,主要是用来做certain checks, tests,conditions
。
解决方案#
- 方案一
删除.git/hooks
文件夹里的pre-commit
文件。如果还是不行可以尝试方案二。
- 方案二
在git commit
的时候加上 --no-verify
。
Github
Github Actions No such file or directory#
问题#
我确定生成了这个文件或文件夹,但是却报找不到文件或文件夹的错误。如下图所示:
我的workflow如下:
name: Build and Deploy
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, 'deploy:') }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Set env
run: |
echo "name=$(echo '${{ github.event.head_commit.message }}' | cut -d ':' -f 2)" >> $GITHUB_ENV
echo "time=$(date +"%Y-%m-%d")" >> $GITHUB_ENV
- name: 安装 Node
uses: actions/setup-node@v3
with:
node-version: "16.15.1" # replace with your node version
- name: cache
uses: actions/cache@v3
id: cache
with:
path: node_modules
key: ${{runner.OS}}-${{hashFiles('**/*-lock.json')}}
- name: Install Dependency
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
sudo apt-get install ghostscript libgs-dev
- name: Build and Export Slides
run: |
echo "${{ env.name }}.md"
npm run build -- ./slides/${{ env.name }}.md --base /slidev_template/${{ env.name }}/
npm run export -- ./slides/${{ env.name }}.md
file_pattern: "*.md ./exports/*.pdf"
- name: Checkout for changes 🛎️
uses: actions/checkout@v3
- name: Compression pdf
run: |
chmod +x shrinkpdf.sh
./shrinkpdf.sh ${{ env.name }}-export.pdf > ./exports/${{ env.name }}.pdf
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: slides/dist # The folder the action should deploy.
target-folder: ${{ env.name }}
clean: false
- name: Update README
run: |
echo "|${{ env.name }}|${{ env.time }}|[https://lizilong1993.github.io/slidev_template/${{ env.name }}](https://lizilong1993.github.io/slidev_template/${{ env.name }}/)|[https://cdn.jsdelivr.net/gh/lizilong1993/slidev_template@main/exports/${{ env.name }}.pdf](https://cdn.jsdelivr.net/gh/lizilong1993/slidev_template@main/exports/${{ env.name }}.pdf)|" >> README.md
echo "|${{ env.name }}|${{ env.time }}|[https://lizilong1993.github.io/slidev_template/${{ env.name }}](https://lizilong1993.github.io/slidev_template/${{ env.name }}/)|[https://cdn.jsdelivr.net/gh/lizilong1993/slidev_template@main/exports/${{ env.name }}.pdf](https://cdn.jsdelivr.net/gh/lizilong1993/slidev_template@main/exports/${{ env.name }}.pdf)|" >> README.CN.md
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automated Change
branch: main
commit_options: "--no-verify --signoff"
解决方案#
因为我错误的在执行这一步之前Check Out了。
我这里是copy别人的代码没仔细审查,导致我工作流开始Check Out后后面中途又一次Check out了。。。
- name: Checkout for changes 🛎️
uses: actions/checkout@v3
- name: Compression pdf
run: |
chmod +x shrinkpdf.sh
./shrinkpdf.sh ${{ env.name }}-export.pdf > ./exports/${{ env.name }}.pdf
可以移除Check Out,影响不大;也可以把Check Out移动到最后面。
Github Actions Permission denied#
执行shrinkpdf.sh
提示拒绝访问。
原因#
权限不够
解决方案#
chmod +x shrinkpdf.sh
sudo ./shrinkpdf.sh in.pdf > out.pdf
kex_exchange_identification: Connection closed by remote host#
未解决,怀疑是Clash导致的,但是网上的解决方案都不行,只能放弃SSH改回HTTPS连接Github了。。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?