git

git

安装与配置

其实也不需要git bash啊,直接终端搞定一切

linux

  1. 用户 git config --list
  2. 配置公私秘钥
    1. cd ~/.ssh
    2. ls
    3. ssh-keygen
    4. cat id_rsa.pub,把输出的加到github ssh里

使用

上传一个项目

  1. 进入文件夹folder_to_upload,git bash(命令行也行,能登陆到github账号就行)
  2. git init
  3. git add .
  4. git commit -m "随便写什么"
  5. github上新建一个仓库,不要勾选Initialize this repository with:Add a README file(创建之后能看到它的教程的)
  6. 将本地仓库与 GitHub 仓库关联git remote add origin https://github.com/用户名/仓库名.git
  7. git branch -M main
  8. git push -u origin main

bash流水线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

# 检查是否提供 commit 信息
if [ -z "$1" ]; then
# 如果没有提供 commit 信息,使用默认值
commit_message="Auto commit: $(date '+%Y-%m-%d %H:%M:%S')"
echo "No commit message provided. Using default: \"$commit_message\""
else
# 使用用户提供的 commit 信息
commit_message="$1"
fi

# 自动添加、提交并推送
git add .
git commit -m "$commit_message"
git push

# 提示完成
echo "Changes have been added, committed with message \"$commit_message\", and pushed successfully!"

报错

权限问题

  1. remote: Support for password authentication was removed on August 13, 2021.
    1. 根据官方教程
    2. Settings,最下面的Developer settings,展开Personal access tokens,选中classic那个,Generate new token
    3. token名字随便,过期、用途选repo
    4. 将令牌复制到剪贴板。关闭页面后不能再出现,除非重新生成!
    5. 设置token,使用,填密码的时候粘贴token
    6. 将分支克隆到本地的仓库(xxx.github.io)中的.git文件夹复制到博客文件夹中
    7. 在博客目录下执行命令同步到远程的hexo分支
      1
      2
      3
      git add -A
      git commit -m "备份Hexo(提交的描述)"
      git push origin hexo

网络问题

  1. Could not resolve host: github.com

.gitignore 文件 强烈建议在新建项目的时候就搞 在里面可以写想忽略的文件或者文件夹,这样git上传的时候就会忽略这个文件

git 合并版本: 前提:从别的库fork了一个,然后写了许多,导致一直是ahead of 某一天库更新了,导致我现在ahead of+ behind。This branch is 12 commits ahead of, 2 commits behind huggingface/lerobot:main. 这种情况怎么办?我已经自己做了一些改动,想合并更新的这两个 应该先拉behind的,跟上库的更新,然后之前ahead of的全推到后面 git remote add upstream https://github.com/huggingface/lerobot.git git fetch upstream git rebase upstream/main 解决完冲突之后git push origin main --force

bash 复制 编辑 解决冲突后 git add <冲突的文件> git rebase --continue