github 杂记

加速下载 github 代码

  • 登录码云—>点击新建仓库—>点击导入已有仓库—>粘贴 github 仓库地址—>点击创建—>好了后直接下载即可

github 获取:token

github token push

  • https://cxvh:${GITHUB_TOKEN}@github.com/cxvh/blogs.git
  • git config --global user.name "cxvh"
  • git config --global user.email "***@qq.com"

发布一个 github packages

  • 初始化 package.json
  • npm init --scope=cxvh中的cxvh必须是你的github用户名,其他随便填写一些description和author,然后一路回车就好。
  • Step 1: 添加 publishConfigpackage.json
    • "publishConfig": { "registry": "https://npm.pkg.github.com/" }
  • Step 2: 登录namegithub登录账号,密码用githubtoken,上面有生成方法,邮箱用github邮箱
    • npm login --registry=https://npm.pkg.github.com/
    • package.json name格式为 @登录名/包名 如:@cxvh/hello-world-npm
  • Step 3: Publish
    • npm publish

github action 配置

根据时间自动构建,文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
on:
schedule: # 自动运行工作流程
- cron: '0 * * * *' # 每小时运行一次(每小时的0分钟开始运行)
# - cron: '0 6 * * *' # 每天运行一次(每天的6时0分钟开始运行)
# - cron: '0 6 1 * *' # 每月运行一次(每月1号的6时0分钟开始运行)
# - cron: '*/30 * * * *' # 每 30 分钟更新一次
# - cron: '0 19 */7 * *' # 应该是每 7 天的 19 时 0 分更新
workflow_dispatch: # 直接通过Github Actions工作流程页面手动运行工作流程(无需等待cron调用)

push 或者 pull_request 触发构建

1
2
3
4
5
6
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

action克隆到当前仓库示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
name: 每天自动同步仓库
on:
schedule:
#- cron: '*/30 * * * *' 每小时的30分钟
- cron: '0 19 * * *'
workflow_dispatch:
jobs:
copy:
runs-on: ubuntu-latest
steps:
- name: 同步到当前仓库
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }} # 具有 repo 权限的 token
# src_path: 改成来源仓库的要拷贝的路径,根目录则填/.
# dst_path: 改成目标仓库的拷贝位置,以斜杠结尾。这里需要填写斜杠非主页仓库名斜杠
# dst_owner: 改成目标仓库所在的用户名
# dst_repo_name: 改成目标仓库名(也就是用户名点github点io)
# dst_branch: 改成目标仓库的分支名
# src_branch: 改成来源仓库的分支名
# clean: true # 这里要保证目标目录先清空,否则非主页仓库若有删除文件就不会同步到主页仓库
# username: 改成操作的用户名
# email: 改成操作用户的邮箱
src_path: /.
dst_path: /
dst_owner: code-ba
dst_repo_name: rss-reader
dst_branch: main
src_branch: main
clean: true # 这里要保证目标目录先清空,否则非主页仓库若有删除文件就不会同步到主页仓库
username: cxvh
email: ${{ secrets.PERSONAL_EMAIL }} # 当前的仓库邮箱

报错解决记录

密钥
  • win生成密钥ssh-keygen写入权限不够报错
    1
    Saving key "\033[A\033[B/c/Users/Baran.Lee/.ssh/id_rsa)\033[D\033[D\033[C\033[\033[D\033[D\033[D\033[D\033[D\033[Dcodeba/id_rsa" failed: No such file or directory
  • 进入文件夹C:\Users\用户\.ssh\gitlab再执行ssh-keygen命令
git rebase
  • 历史中不连续的commit合并 git rebase -i head~3,然后报错如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    interactive rebase in progress; onto bbef1ea
    No commands done.
    Next commands to do (3 remaining commands):
    s ae093ef 更新 circleci 配置文件
    s 1ab23ac 更新 circleci 配置文件2
    (use "git rebase --edit-todo" to view and edit)
    You are currently editing a commit while rebasing branch 'main' on 'bbef1ea'.
    (use "git commit --amend" to amend the current commit)
    (use "git rebase --continue" once you are satisfied with your changes)

    nothing to commit, working tree clean
  • 回到rebase执行之前的状态 git rebase --abort
git push
  • git push orgin main
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    fatal: 'orgin' does not appear to be a git repository
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
    #
    $ git push orgin主要
    致命的:“orgin”似乎不是git存储库
    致命:无法从远程存储库读取。

    请确保您具有正确的访问权限
    并且存储库存在。
  • 删掉.git目录,重新配置 git init…
git push提交会提示
1
fatal: unable to access 'https://github.com/cxvh/cxvh-cli-test.git/': OpenSSL SSL_connect: Connection was reset in connection to github.com:443

https链接改为ssh链接即可:git remote set-url origin git@github.com:cxvh/cxvh-cli-test.git