完整命令
Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
Guides
- gitattributes
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- Glossary
- Hooks
- gitignore
- gitmodules
- Revisions
- Submodules
- Tutorial
- Workflows
- All guides…
External Systems
Administration
Server Admin
Plumbing Commands
- cat-file
- check-ignore
- checkout-index
- commit-tree
- count-objects
- diff-index
- for-each-ref
- hash-object
- ls-files
- ls-tree
- merge-base
- read-tree
- rev-list
- rev-parse
- show-ref
- symbolic-ref
- update-index
- update-ref
- verify-pack
- write-tree
常用命令
服务器安装
yum -y install git-core
git --version
绑定git地址
git init
git remote add origin http://github.com/example.git
git add .
git commit -m ":tada: init"
git branch --set-upstream-to=origin/master master
git push
拉取分支
git pull origin master
git clean -d -fx
-n
显示将要删除的文件和目录-x
删除忽略文件已经对git来说不识别的文件-d
删除未被添加到git的路径中的文件-f
强制运行
忽略本地历史提交冲突强制合并
git remote add platform https://192.168.100.49:8081/zhcloud/zh-web.git
git fetch platform
git merge platform/master --allow-unrelated-histories
切换分支
git checkout master
git checkout -b project
git branch
回退数据库版本
git reset --hard 版本信息SHA
git push -f -u origin prod
标签
git tag # 打印所有标签
git tag -l 1.*.* # 打印所有标签
git checkout 1.0.0 # 查看对应标签状态
git tag 1.0.0-light # 创建轻量标签
git tag -a 1.0.0 -m "这是备注信息" # 创建带备注标签(推荐)
git tag -a 1.0.0 0c3b62d -m "这是备注信息" # 针对特定commit版本SHA创建标签
git tag -d 1.0.0 # 删除标签(本地)
git push origin --tags # 将本地标签发布到远程仓库
git push origin 1.0.0 # 指定版本发送
git push origin --delete 1.0.0 # 删除远程仓库对应标签
全局信息查看
git remote show origin # 代码源
git remote remove origin # 删除代码源
git config -l # 全局级配置,如果没有仓库级别的特殊配置,默认读取这个配置; 仓库级配置,一般一个项目配置一次
git config --global user.name "name"
git config --system --unset credential.helper # 用户密码更改后重新设置
git config --global http.sslVerify false # 解决SSL验证的问题
git config --global --unset http.proxy # 解决SSL验证的问题
子模块
# 添加子模块
git submodule add git@github.com:WANGJUEYA/hexo-theme-christmas-tree.git ./themes/christmas-tree
# 删除子模块缓存(用于手动删除子模块后提示仍然存在的问题)
git rm -r --cached themes/christmas-tree
# 首次拉取包含子模块的代码(windows子模块ssh验证有问题, 试用git的命令行客户端 git-bash 处理)
git clone git@github.com:WANGJUEYA/B612-Factory.git --recursive
# 第一次初始化所有子模块子模块
git submodule update --init --recursive
# 更新所有子模块到最新版本
git submodule update --remote
使用ssh协议拉取代码
- 配置全局配置
$ git config --global user.name "GitHub用户名"
$ git config --global user.email "GitHub绑定邮箱"
-
输入命令, 一直回车生成文件
-
注意: 如果我们
Enter passphrase
传入了值, 会遇到一系列问题, 建议直接回车不传值- 拉取带子模块的仓库时失败, 需要用
git-bash
客户端构建 - GitHub Action 构建时无法传入key(暂未找到解决方案)
- 拉取带子模块的仓库时失败, 需要用
$ ssh-keygen -m PEM -t rsa -b 4096 -C "{注册邮箱地址}"
- 打开
C:\Users\用户名\.ssh\id_rsa.pub
, 复制内容 - 在gitee及github设置中新增ssh
- 之后设置remote代码源时需要指定为ssh协议
git@github.com:username
异常解决
Load key “/home/runner/.ssh/id_rsa”: invalid format
GitHub Action构建时出现
- 应当使用
-m PEM
参数
ssh:connect to host github.com port 22: Connection timed out
- 更改端口
cd C:/user/.ssh/config
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
# 检测配置是否成功
ssh -T git@github.com
Gitmoji
An emoji guide for your commit messages
icon | show | key | remark |
---|---|---|---|
🎨 | 🎨 | art | Improve structure / format of the code. |
⚡️ | ⚡ | zap | Improve performance. |
🔥 | 🔥 | fire | Remove code or files. |
🐛 | 🐛 | bug | Fix a bug. |
🚑️ | 🚑 | ambulance | Critical hotfix. |
✨ | ✨ | sparkles | Introduce new features. |
📝 | 📝 | memo | Add or update documentation. |
🚀 | 🚀 | rocket | Deploy stuff. |
💄 | 💄 | lipstick | Add or update the UI and style files. |
🎉 | 🎉 | tada | Begin a project. |
✅ | ✅ | white_check_mark | Add, update, or pass tests. |
🔒️ | 🔒 | lock | Fix security issues. |
🔐 | 🔐 | closed_lock_with_key | Add or update secrets. |
🔖 | 🔖 | bookmark | Release / Version tags. |
🚨 | 🚨 | rotating_light | Fix compiler / linter warnings. |
🚧 | 🚧 | construction | Work in progress. |
💚 | 💚 | green_heart | Fix CI Build. |
⬇️ | ⬇ | arrow_down | Downgrade dependencies. |
⬆️ | ⬆ | arrow_up | Upgrade dependencies. |
📌 | 📌 | pushpin | Pin dependencies to specific versions. |
👷 | 👷 | construction_worker | Add or update CI build system. |
📈 | 📈 | chart_with_upwards_trend | Add or update analytics or track code. |
♻️ | ♻ | recycle | Refactor code. |
➕ | ➕ | heavy_plus_sign | Add a dependency. |
➖ | ➖ | heavy_minus_sign | Remove a dependency. |
🔧 | 🔧 | wrench | Add or update configuration files. |
🔨 | 🔨 | hammer | Add or update development scripts. |
🌐 | 🌐 | globe_with_meridians | Internationalization and localization. |
✏️ | ✏ | pencil2 | Fix typos. |
💩 | 💩 | poop | Write bad code that needs to be improved. |
⏪️ | ⏪ | rewind | Revert changes. |
🔀 | 🔀 | twisted_rightwards_arrows | Merge branches. |
📦️ | 📦 | package | Add or update compiled files or packages. |
👽️ | 👽 | alien | Update code due to external API changes. |
🚚 | 🚚 | truck | Move or rename resources (e.g.: files, paths, routes). |
📄 | 📄 | page_facing_up | Add or update license. |
💥 | 💥 | boom | Introduce breaking changes. |
🍱 | 🍱 | bento | Add or update assets. |
♿️ | ♿ | wheelchair | Improve accessibility. |
💡 | 💡 | bulb | Add or update comments in source code. |
🍻 | 🍻 | beers | Write code drunkenly. |
💬 | 💬 | speech_balloon | Add or update text and literals. |
🗃️ | 🗃 | card_file_box | Perform database related changes. |
🔊 | 🔊 | loud_sound | Add or update logs. |
🔇 | 🔇 | mute | Remove logs. |
👥 | 👥 | busts_in_silhouette | Add or update contributor(s). |
🚸 | 🚸 | children_crossing | Improve user experience / usability. |
🏗️ | 🏗 | building_construction | Make architectural changes. |
📱 | 📱 | iphone | Work on responsive design. |
🤡 | 🤡 | clown_face | Mock things. |
🥚 | 🥚 | egg | Add or update an easter egg. |
🙈 | 🙈 | see_no_evil | Add or update a .gitignore file. |
📸 | 📸 | camera_flash | Add or update snapshots. |
⚗️ | ⚗ | alembic | Perform experiments. |
🔍️ | 🔍 | mag | Improve SEO. |
🏷️ | 🏷 | label | Add or update types. |
🌱 | 🌱 | seedling | Add or update seed files. |
🚩 | 🚩 | triangular_flag_on_post | Add, update, or remove feature flags. |
🥅 | 🥅 | goal_net | Catch errors. |
💫 | 💫 | dizzy | Add or update animations and transitions. |
🗑️ | 🗑 | wastebasket | Deprecate code that needs to be cleaned up. |
🛂 | 🛂 | passport_control | Work on code related to authorization, roles and permissions. |
🩹 | 🩹 | adhesive_bandage | Simple fix for a non-critical issue. |
🧐 | 🧐 | monocle_face | Data exploration/inspection. |
⚰️ | ⚰ | coffin | Remove dead code. |
🧪 | 🧪 | test_tube | Add a failing test. |
👔 | 👔 | necktie | Add or update business logic |
🩺 | 🩺 | stethoscope | Add or update healthcheck. |
🧱 | 🧱 | bricks | Infrastructure related changes. |
🧑💻 | 🧑💻 | technologist | Improve developer experience |
💸 | 💸 | money_with_wings | Add sponsorships or money related infrastructure. |
🧵 | 🧵 | thread | Add or update code related to multithreading or concurrency. |
github
GitHub Action
官方文档: https://docs.github.com/en/actions/quickstart
利用 GitHub Action 实现仓库同步
name: Sync To Parent Repository
on: [ push, delete, create ]
jobs:
git-mirror:
runs-on: ubuntu-latest
steps:
- name: Configure Private Key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Push Mirror
env:
PARENT_REPOSITORY: 'git@github.com:WANGJUEYA/B612-Factory.git'
USER_NAME: 'wangjueya_ci'
USER_EMAIL: '573711282@qq.com'
run: |
git config --global user.name "$USER_NAME"
git config --global user.email "$USER_EMAIL"
git clone "$PARENT_REPOSITORY" Repository --recursive
cd Repository
git submodule update --remote
git add *
git commit -m ":construction_worker: Auto Sync"
git push
利用 GitHub Action 实现网站发布
name: Sync To Parent Repository
on: [ push, delete, create ]
jobs:
hexo-deploy:
runs-on: ubuntu-latest
steps:
- name: Configure Private Key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: git config
env:
USER_NAME: 'wangjueya_ci'
USER_EMAIL: '573711282@qq.com'
run: |
git config --global user.name "$USER_NAME"
git config --global user.email "$USER_EMAIL"
git config --global core.quotepath false
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Git commit
run: |
git submodule update --init --recursive
git submodule update --remote
echo "构建时提交一份最新的代码"
git add *
git commit -m ":construction_worker: [skip ci] Auto Update" | if [[ $? == 0 ]]; then
git push origin master
fi
- uses: c-hive/gha-yarn-cache@v1
- name: Yarn install
run: |
echo "修复自动构建时所有文章更新时间为当前时间问题 | 取git提交时间"
cd source/_posts # 子模块更新失败问题
git ls-tree -r --name-only HEAD | while read filename; do
echo $filename;
unixtime=$(git log -1 --format="%at" -- "${filename}");
touchtime=$(date -d @$unixtime +'%Y%m%d%H%M.%S');
echo "${filename} --- ${touchtime}"
touch -t ${touchtime} "${filename}";
done
cd ../../
yarn install
- name: Hexo deploy
run: |
yarn run clean
yarn run deploy
注意: secrets.SSH_PRIVATE_KEY
在 每个仓库下 setting > secrets 设置
某次提交不触发构建
https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
Workflows that would otherwise be triggered using on: push
or on: pull_request
won’t be triggered if you add any of the following strings to the commit message in a push, or the HEAD commit of a pull request:
提交中包含以下文本会跳过对应的触发
[skip ci]
[ci skip]
[no ci]
[skip actions]
[actions skip]
Alternatively, you can end the commit message with two empty lines followed by either:
skip-checks:true
skip-checks: true