Knowledge Observatory Obsidian notes, RSS insights, and lightweight AI summaries.
2026年4月4日 未分类

2.4.2 Git常见指令

常见指令

git init 	
git status 	# 查询状态

git add .
#重新规范化,依据当的 `.gitattributes` 或 `core.autocrlf`配置重新处理文件内容
git add --renormalize .      

git commit -m "first commit"
git remote add origin "你的GitHub仓库的SSH链接"
# 如果origin已经存在,替换为你的 GitHub 私有库地址
git remote set-url origin https://github.com/你的用户名/my-quartz-site.git
# 如果origin不存在
git remote add origin xxx

# 查询当前分支是什么
git branch
# 把本地分支从master改名为main
git branch -M main

git pull origin main --allow-unrelated-histories
#合并分支
git add .
git commit -m "merge: resolve conflict"

git push -u origin main
git push origin main -f 

git remote -v    #确认自己输出的是哪个库

git clone xxx .

-u--set-upstream 的缩写。它的作用是在本地分支与远程分支之间建立一个“持久的绑定关系”,Git 会记住你当前的 main 分支应该对应 GitHub 上的 origin/main

查询 git 版本信息

git
git -v

当前 commit 中含有大于 1000 mb 的大文件解决办法

只推送干净 commit(临时、安全)

  1. 创建一个新的 孤立分支(--orphan

  2. 添加当前工作区文件(不包含历史大文件)

  3. commit 并强制推送

# 1. 新建孤立分支
git checkout --orphan beta-version

# 2. 添加所有文件
git add .

# 3. 新 commit
git commit -m "Clean push without large files"

# 4. 推送到远程 main
git push origin beta-version:main --force

其他指令

1. 不让 github 在每次推送时自动运行

# 临时停用GitHub Actions,在某一次 push 时不让它运行
git commit -m "update skills [skip ci]"
  • 有效关键词[skip ci], [ci skip], [no ci], skip-checks: true
  • 效果:GitHub 看到这些词会自动忽略这次推送,不触发任何 Action。这对你刚才那种反复调整 .gitignore 的小操作非常有用。

当然也可以将 .github/workflows/你的文件.yml 里的 on: push 改为 on: workflow_dispatch

name: My Workflow
on:
  workflow_dispatch: # 只要这一行,它就不会随 push 运行了
  • 效果:代码推送到 GitHub 后,Actions 不会自动运行。
  • 如何运行:你需要手动去 GitHub 网页 -> Actions 选项卡 -> 选择该工作流 -> 点击右侧的 Run workflow 按钮。