重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
git-essentials by sundial-org/awesome-openclaw-skills
npx skills add https://github.com/sundial-org/awesome-openclaw-skills --skill git-essentials版本控制和协作必备的 Git 命令。
# 配置用户
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
# 初始化仓库
git init
# 克隆仓库
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git custom-name
# 检查状态
git status
# 添加文件到暂存区
git add file.txt
git add .
git add -A # 包含删除的所有更改
# 提交更改
git commit -m "Commit message"
# 一步完成添加和提交
git commit -am "Message"
# 修改最后一次提交
git commit --amend -m "New message"
git commit --amend --no-edit # 保留原提交信息
# 显示未暂存的更改
git diff
# 显示已暂存的更改
git diff --staged
# 显示特定文件的更改
git diff file.txt
# 显示两次提交之间的更改
git diff commit1 commit2
# 列出分支
git branch
git branch -a # 包含远程分支
# 创建分支
git branch feature-name
# 切换分支
git checkout feature-name
git switch feature-name # 现代替代命令
# 创建并切换分支
git checkout -b feature-name
git switch -c feature-name
# 删除分支
git branch -d branch-name
git branch -D branch-name # 强制删除
# 重命名分支
git branch -m old-name new-name
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 将分支合并到当前分支
git merge feature-name
# 合并时不使用快进模式
git merge --no-ff feature-name
# 中止合并
git merge --abort
# 显示合并冲突
git diff --name-only --diff-filter=U
# 列出远程仓库
git remote -v
# 添加远程仓库
git remote add origin https://github.com/user/repo.git
# 更改远程仓库 URL
git remote set-url origin https://github.com/user/new-repo.git
# 移除远程仓库
git remote remove origin
# 从远程仓库获取
git fetch origin
# 拉取更改(获取 + 合并)
git pull
# 使用变基方式拉取
git pull --rebase
# 推送更改
git push
# 推送新分支
git push -u origin branch-name
# 强制推送(谨慎使用!)
git push --force-with-lease
# 显示提交历史
git log
# 每行显示一个提交
git log --oneline
# 带图形显示
git log --graph --oneline --all
# 最近 N 次提交
git log -5
# 按作者显示提交
git log --author="Name"
# 显示日期范围内的提交
git log --since="2 weeks ago"
git log --until="2024-01-01"
# 文件历史
git log -- file.txt
# 搜索提交信息
git log --grep="bug fix"
# 搜索代码更改
git log -S "function_name"
# 显示每行的修改者
git blame file.txt
# 查找引入错误的提交
git bisect start
git bisect bad
git bisect good commit-hash
# 丢弃文件中的更改
git restore file.txt
git checkout -- file.txt # 旧方式
# 丢弃所有更改
git restore .
# 取消暂存文件
git restore --staged file.txt
git reset HEAD file.txt # 旧方式
# 取消所有暂存
git reset
# 撤销最后一次提交(保留更改)
git reset --soft HEAD~1
# 撤销最后一次提交(丢弃更改)
git reset --hard HEAD~1
# 还原提交(创建新提交)
git revert commit-hash
# 重置到特定提交
git reset --hard commit-hash
# 储藏更改
git stash
# 带信息储藏
git stash save "Work in progress"
# 列出储藏
git stash list
# 应用最新的储藏
git stash apply
# 应用并移除储藏
git stash pop
# 应用特定储藏
git stash apply stash@{2}
# 删除储藏
git stash drop stash@{0}
# 清除所有储藏
git stash clear
# 变基当前分支
git rebase main
# 交互式变基(最近 3 次提交)
git rebase -i HEAD~3
# 解决冲突后继续
git rebase --continue
# 跳过当前提交
git rebase --skip
# 中止变基
git rebase --abort
# 列出标签
git tag
# 创建轻量标签
git tag v1.0.0
# 创建附注标签
git tag -a v1.0.0 -m "Version 1.0.0"
# 为特定提交打标签
git tag v1.0.0 commit-hash
# 推送标签
git push origin v1.0.0
# 推送所有标签
git push --tags
# 删除标签
git tag -d v1.0.0
git push origin --delete v1.0.0
# 应用特定提交
git cherry-pick commit-hash
# 拣选但不提交
git cherry-pick -n commit-hash
# 添加子模块
git submodule add https://github.com/user/repo.git path/
# 初始化子模块
git submodule init
# 更新子模块
git submodule update
# 克隆包含子模块的仓库
git clone --recursive https://github.com/user/repo.git
# 预览将被删除的文件
git clean -n
# 删除未跟踪的文件
git clean -f
# 删除未跟踪的文件和目录
git clean -fd
# 包含被忽略的文件
git clean -fdx
功能分支工作流:
git checkout -b feature/new-feature
# 进行更改
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
# 创建 PR,合并后:
git checkout main
git pull
git branch -d feature/new-feature
热修复工作流:
git checkout main
git pull
git checkout -b hotfix/critical-bug
# 修复错误
git commit -am "Fix critical bug"
git push -u origin hotfix/critical-bug
# 合并后:
git checkout main && git pull
同步复刻仓库:
git remote add upstream https://github.com/original/repo.git
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
添加到 ~/.gitconfig:
[alias]
st = status
co = checkout
br = branch
ci = commit
unstage = reset HEAD --
last = log -1 HEAD
visual = log --graph --oneline --all
amend = commit --amend --no-edit
.gitignore 排除文件--force-with-lease 替代 --force撤销意外提交:
git reset --soft HEAD~1
恢复已删除的分支:
git reflog
git checkout -b branch-name <commit-hash>
修复错误的提交信息:
git commit --amend -m "Correct message"
解决合并冲突:
# 编辑文件以解决冲突
git add resolved-files
git commit # 或 git merge --continue
官方文档:https://git-scm.com/doc Pro Git 书籍:https://git-scm.com/book 可视化 Git 指南:https://marklodato.github.io/visual-git-guide/
每周安装次数
48
仓库
GitHub 星标数
538
首次出现
2026年2月27日
安全审计
安装于
gemini-cli47
github-copilot47
amp47
cline47
codex47
kimi-cli47
Essential Git commands for version control and collaboration.
# Configure user
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
# Initialize repository
git init
# Clone repository
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git custom-name
# Check status
git status
# Add files to staging
git add file.txt
git add .
git add -A # All changes including deletions
# Commit changes
git commit -m "Commit message"
# Add and commit in one step
git commit -am "Message"
# Amend last commit
git commit --amend -m "New message"
git commit --amend --no-edit # Keep message
# Show unstaged changes
git diff
# Show staged changes
git diff --staged
# Show changes in specific file
git diff file.txt
# Show changes between commits
git diff commit1 commit2
# List branches
git branch
git branch -a # Include remote branches
# Create branch
git branch feature-name
# Switch branch
git checkout feature-name
git switch feature-name # Modern alternative
# Create and switch
git checkout -b feature-name
git switch -c feature-name
# Delete branch
git branch -d branch-name
git branch -D branch-name # Force delete
# Rename branch
git branch -m old-name new-name
# Merge branch into current
git merge feature-name
# Merge with no fast-forward
git merge --no-ff feature-name
# Abort merge
git merge --abort
# Show merge conflicts
git diff --name-only --diff-filter=U
# List remotes
git remote -v
# Add remote
git remote add origin https://github.com/user/repo.git
# Change remote URL
git remote set-url origin https://github.com/user/new-repo.git
# Remove remote
git remote remove origin
# Fetch from remote
git fetch origin
# Pull changes (fetch + merge)
git pull
# Pull with rebase
git pull --rebase
# Push changes
git push
# Push new branch
git push -u origin branch-name
# Force push (careful!)
git push --force-with-lease
# Show commit history
git log
# One line per commit
git log --oneline
# With graph
git log --graph --oneline --all
# Last N commits
git log -5
# Commits by author
git log --author="Name"
# Commits in date range
git log --since="2 weeks ago"
git log --until="2024-01-01"
# File history
git log -- file.txt
# Search commit messages
git log --grep="bug fix"
# Search code changes
git log -S "function_name"
# Show who changed each line
git blame file.txt
# Find commit that introduced bug
git bisect start
git bisect bad
git bisect good commit-hash
# Discard changes in file
git restore file.txt
git checkout -- file.txt # Old way
# Discard all changes
git restore .
# Unstage file
git restore --staged file.txt
git reset HEAD file.txt # Old way
# Unstage all
git reset
# Undo last commit (keep changes)
git reset --soft HEAD~1
# Undo last commit (discard changes)
git reset --hard HEAD~1
# Revert commit (create new commit)
git revert commit-hash
# Reset to specific commit
git reset --hard commit-hash
# Stash changes
git stash
# Stash with message
git stash save "Work in progress"
# List stashes
git stash list
# Apply latest stash
git stash apply
# Apply and remove stash
git stash pop
# Apply specific stash
git stash apply stash@{2}
# Delete stash
git stash drop stash@{0}
# Clear all stashes
git stash clear
# Rebase current branch
git rebase main
# Interactive rebase (last 3 commits)
git rebase -i HEAD~3
# Continue after resolving conflicts
git rebase --continue
# Skip current commit
git rebase --skip
# Abort rebase
git rebase --abort
# List tags
git tag
# Create lightweight tag
git tag v1.0.0
# Create annotated tag
git tag -a v1.0.0 -m "Version 1.0.0"
# Tag specific commit
git tag v1.0.0 commit-hash
# Push tag
git push origin v1.0.0
# Push all tags
git push --tags
# Delete tag
git tag -d v1.0.0
git push origin --delete v1.0.0
# Apply specific commit
git cherry-pick commit-hash
# Cherry-pick without committing
git cherry-pick -n commit-hash
# Add submodule
git submodule add https://github.com/user/repo.git path/
# Initialize submodules
git submodule init
# Update submodules
git submodule update
# Clone with submodules
git clone --recursive https://github.com/user/repo.git
# Preview files to be deleted
git clean -n
# Delete untracked files
git clean -f
# Delete untracked files and directories
git clean -fd
# Include ignored files
git clean -fdx
Feature branch workflow:
git checkout -b feature/new-feature
# Make changes
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
# Create PR, then after merge:
git checkout main
git pull
git branch -d feature/new-feature
Hotfix workflow:
git checkout main
git pull
git checkout -b hotfix/critical-bug
# Fix bug
git commit -am "Fix critical bug"
git push -u origin hotfix/critical-bug
# After merge:
git checkout main && git pull
Syncing fork:
git remote add upstream https://github.com/original/repo.git
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
Add to ~/.gitconfig:
[alias]
st = status
co = checkout
br = branch
ci = commit
unstage = reset HEAD --
last = log -1 HEAD
visual = log --graph --oneline --all
amend = commit --amend --no-edit
.gitignore for files to exclude--force-with-lease instead of --forceUndo accidental commit:
git reset --soft HEAD~1
Recover deleted branch:
git reflog
git checkout -b branch-name <commit-hash>
Fix wrong commit message:
git commit --amend -m "Correct message"
Resolve merge conflicts:
# Edit files to resolve conflicts
git add resolved-files
git commit # Or git merge --continue
Official docs: https://git-scm.com/doc Pro Git book: https://git-scm.com/book Visual Git guide: https://marklodato.github.io/visual-git-guide/
Weekly Installs
48
Repository
GitHub Stars
538
First Seen
Feb 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli47
github-copilot47
amp47
cline47
codex47
kimi-cli47
Standup 站会助手:自动生成每日站会更新,集成代码、工单和聊天工具
752 周安装