npx skills add https://github.com/akillness/oh-my-skills --skill git-workflow创建功能分支 :
# 创建并切换到新分支
git checkout -b feature/feature-name
# 或从特定提交创建
git checkout -b feature/feature-name <commit-hash>
命名规范 :
feature/description: 新功能bugfix/description: 错误修复hotfix/description: 紧急修复refactor/description: 代码重构docs/description: 文档更新广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
暂存更改 :
# 暂存特定文件
git add file1.py file2.js
# 暂存所有更改
git add .
# 使用补丁模式暂存(交互式)
git add -p
检查状态 :
# 查看更改内容
git status
# 查看详细差异
git diff
# 查看已暂存的差异
git diff --staged
编写良好的提交信息 :
git commit -m "type(scope): subject
Detailed description of what changed and why.
- Change 1
- Change 2
Fixes #123"
提交类型 :
feat: 新功能fix: 错误修复docs: 文档style: 格式化,无代码更改refactor: 代码重构test: 添加测试chore: 维护任务示例 :
git commit -m "feat(auth): add JWT authentication
- Implement JWT token generation
- Add token validation middleware
- Update user model with refresh token
Closes #42"
# 推送到远程仓库
git push origin feature/feature-name
# 强制推送(谨慎使用!)
git push origin feature/feature-name --force-with-lease
# 设置上游并推送
git push -u origin feature/feature-name
# 拉取最新更改
git pull origin main
# 使用变基拉取(历史更清晰)
git pull --rebase origin main
# 仅获取不合并
git fetch origin
合并功能分支 :
# 切换到主分支
git checkout main
# 合并功能分支
git merge feature/feature-name
# 使用非快进合并(创建合并提交)
git merge --no-ff feature/feature-name
使用变基替代合并 :
# 在功能分支上
git checkout feature/feature-name
# 变基到主分支
git rebase main
# 解决冲突后继续
git rebase --continue
# 中止变基
git rebase --abort
发生冲突时 :
# 查看冲突文件
git status
# 打开文件并解决冲突
# 查找标记:
<<<<<<< HEAD
Current branch code
=======
Incoming branch code
>>>>>>> feature-branch
# 解决后
git add <resolved-files>
git commit # 用于合并
git rebase --continue # 用于变基
# 删除本地分支
git branch -d feature/feature-name
# 强制删除
git branch -D feature/feature-name
# 删除远程分支
git push origin --delete feature/feature-name
# 清理过时的引用
git fetch --prune
# 变基最近 3 个提交
git rebase -i HEAD~3
# 编辑器中的命令:
# pick: 使用提交
# reword: 更改提交信息
# edit: 修改提交
# squash: 与上一个提交合并
# fixup: 类似 squash,但丢弃信息
# drop: 移除提交
# 暂存当前更改
git stash
# 带消息暂存
git stash save "Work in progress on feature X"
# 列出暂存
git stash list
# 应用最近的暂存
git stash apply
# 应用并移除暂存
git stash pop
# 应用特定暂存
git stash apply stash@{2}
# 丢弃暂存
git stash drop stash@{0}
# 清除所有暂存
git stash clear
# 应用特定提交
git cherry-pick <commit-hash>
# 拣选多个提交
git cherry-pick <hash1> <hash2> <hash3>
# 拣选但不提交
git cherry-pick -n <commit-hash>
# 开始二分查找
git bisect start
# 标记当前为错误
git bisect bad
# 标记已知正确的提交
git bisect good <commit-hash>
# Git 将检出提交以供测试
# 测试并标记每个:
git bisect good # 如果工作正常
git bisect bad # 如果损坏
# 找到后,重置
git bisect reset
# 1. 创建功能分支
git checkout main
git pull origin main
git checkout -b feature/user-profile
# 2. 进行更改
# ... 编辑文件 ...
# 3. 提交更改
git add src/profile/
git commit -m "feat(profile): add user profile page
- Create profile component
- Add profile API endpoints
- Add profile tests"
# 4. 与主分支保持同步
git fetch origin
git rebase origin/main
# 5. 推送到远程仓库
git push origin feature/user-profile
# 6. 在 GitHub/GitLab 上创建 Pull Request
# ... 经过审查和批准后 ...
# 7. 合并并清理
git checkout main
git pull origin main
git branch -d feature/user-profile
# 1. 从生产环境创建热修复分支
git checkout main
git pull origin main
git checkout -b hotfix/critical-bug
# 2. 修复错误
# ... 进行修复 ...
# 3. 提交
git add .
git commit -m "hotfix: fix critical login bug
Fixes authentication bypass vulnerability
Fixes #999"
# 4. 立即推送和合并
git push origin hotfix/critical-bug
# 合并后:
# 5. 清理
git checkout main
git pull origin main
git branch -d hotfix/critical-bug
# 1. 更新主分支
git checkout main
git pull origin main
# 2. 创建功能分支
git checkout -b feature/new-feature
# 3. 定期从主分支更新
git fetch origin
git rebase origin/main
# 4. 推送你的工作
git push origin feature/new-feature
# 5. 如果队友对你的分支进行了更改
git pull origin feature/new-feature --rebase
# 6. 解决任何冲突
# ... 解决冲突 ...
git add .
git rebase --continue
# 7. 变基后强制推送
git push origin feature/new-feature --force-with-lease
git reset --soft HEAD~1
git reset --hard HEAD~1
# 更改提交信息
git commit --amend -m "New message"
# 添加文件到最后一次提交
git add forgotten-file.txt
git commit --amend --no-edit
# 详细日志
git log
# 每行一个提交
git log --oneline
# 带图形
git log --oneline --graph --all
# 最近 5 个提交
git log -5
# 按作者查看提交
git log --author="John"
# 日期范围内的提交
git log --since="2 weeks ago"
# 搜索提交信息
git log --grep="keyword"
# 搜索代码更改
git log -S "function_name"
# 显示文件历史记录
git log --follow -- path/to/file
# 1. 从当前状态创建正确的分支
git branch feature/correct-branch
# 2. 重置当前分支
git reset --hard HEAD~1
# 3. 切换到正确分支
git checkout feature/correct-branch
# 如果尚未推送
git reset --hard HEAD~1
# 如果已推送(创建还原提交)
git revert -m 1 <merge-commit-hash>
# 查找丢失的提交
git reflog
# 从丢失的提交创建分支
git checkout -b recovered-branch <commit-hash>
# 添加上游远程仓库
git remote add upstream https://github.com/original/repo.git
# 获取上游
git fetch upstream
# 合并上游主分支
git checkout main
git merge upstream/main
# 推送到你的分叉
git push origin main
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.lg 'log --oneline --graph --all'
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
每周安装数
1
仓库
GitHub 星标数
3
首次出现
1 天前
安全审计
安装于
mcpjam1
claude-code1
junie1
windsurf1
zencoder1
crush1
Create feature branch :
# Create and switch to new branch
git checkout -b feature/feature-name
# Or create from specific commit
git checkout -b feature/feature-name <commit-hash>
Naming conventions :
feature/description: New featuresbugfix/description: Bug fixeshotfix/description: Urgent fixesrefactor/description: Code refactoringdocs/description: Documentation updatesStage changes :
# Stage specific files
git add file1.py file2.js
# Stage all changes
git add .
# Stage with patch mode (interactive)
git add -p
Check status :
# See what's changed
git status
# See detailed diff
git diff
# See staged diff
git diff --staged
Write good commit messages :
git commit -m "type(scope): subject
Detailed description of what changed and why.
- Change 1
- Change 2
Fixes #123"
Commit types :
feat: New featurefix: Bug fixdocs: Documentationstyle: Formatting, no code changerefactor: Code refactoringtest: Adding testschore: MaintenanceExample :
git commit -m "feat(auth): add JWT authentication
- Implement JWT token generation
- Add token validation middleware
- Update user model with refresh token
Closes #42"
# Push to remote
git push origin feature/feature-name
# Force push (use with caution!)
git push origin feature/feature-name --force-with-lease
# Set upstream and push
git push -u origin feature/feature-name
# Pull latest changes
git pull origin main
# Pull with rebase (cleaner history)
git pull --rebase origin main
# Fetch without merging
git fetch origin
Merge feature branch :
# Switch to main branch
git checkout main
# Merge feature
git merge feature/feature-name
# Merge with no fast-forward (creates merge commit)
git merge --no-ff feature/feature-name
Rebase instead of merge :
# On feature branch
git checkout feature/feature-name
# Rebase onto main
git rebase main
# Continue after resolving conflicts
git rebase --continue
# Abort rebase
git rebase --abort
When conflicts occur :
# See conflicted files
git status
# Open files and resolve conflicts
# Look for markers:
<<<<<<< HEAD
Current branch code
=======
Incoming branch code
>>>>>>> feature-branch
# After resolving
git add <resolved-files>
git commit # For merge
git rebase --continue # For rebase
# Delete local branch
git branch -d feature/feature-name
# Force delete
git branch -D feature/feature-name
# Delete remote branch
git push origin --delete feature/feature-name
# Clean up stale references
git fetch --prune
# Rebase last 3 commits
git rebase -i HEAD~3
# Commands in editor:
# pick: use commit
# reword: change commit message
# edit: amend commit
# squash: combine with previous
# fixup: like squash, discard message
# drop: remove commit
# Stash current changes
git stash
# Stash with message
git stash save "Work in progress on feature X"
# List stashes
git stash list
# Apply most recent stash
git stash apply
# Apply and remove stash
git stash pop
# Apply specific stash
git stash apply stash@{2}
# Drop stash
git stash drop stash@{0}
# Clear all stashes
git stash clear
# Apply specific commit
git cherry-pick <commit-hash>
# Cherry-pick multiple commits
git cherry-pick <hash1> <hash2> <hash3>
# Cherry-pick without committing
git cherry-pick -n <commit-hash>
# Start bisect
git bisect start
# Mark current as bad
git bisect bad
# Mark known good commit
git bisect good <commit-hash>
# Git will checkout commits to test
# Test and mark each:
git bisect good # if works
git bisect bad # if broken
# When found, reset
git bisect reset
# 1. Create feature branch
git checkout main
git pull origin main
git checkout -b feature/user-profile
# 2. Make changes
# ... edit files ...
# 3. Commit changes
git add src/profile/
git commit -m "feat(profile): add user profile page
- Create profile component
- Add profile API endpoints
- Add profile tests"
# 4. Keep up to date with main
git fetch origin
git rebase origin/main
# 5. Push to remote
git push origin feature/user-profile
# 6. Create Pull Request on GitHub/GitLab
# ... after review and approval ...
# 7. Merge and cleanup
git checkout main
git pull origin main
git branch -d feature/user-profile
# 1. Create hotfix branch from production
git checkout main
git pull origin main
git checkout -b hotfix/critical-bug
# 2. Fix the bug
# ... make fixes ...
# 3. Commit
git add .
git commit -m "hotfix: fix critical login bug
Fixes authentication bypass vulnerability
Fixes #999"
# 4. Push and merge immediately
git push origin hotfix/critical-bug
# After merge:
# 5. Cleanup
git checkout main
git pull origin main
git branch -d hotfix/critical-bug
# 1. Update main branch
git checkout main
git pull origin main
# 2. Create feature branch
git checkout -b feature/new-feature
# 3. Regular updates from main
git fetch origin
git rebase origin/main
# 4. Push your work
git push origin feature/new-feature
# 5. If teammate made changes to your branch
git pull origin feature/new-feature --rebase
# 6. Resolve any conflicts
# ... resolve conflicts ...
git add .
git rebase --continue
# 7. Force push after rebase
git push origin feature/new-feature --force-with-lease
git reset --soft HEAD~1
git reset --hard HEAD~1
# Change commit message
git commit --amend -m "New message"
# Add files to last commit
git add forgotten-file.txt
git commit --amend --no-edit
# Detailed log
git log
# One line per commit
git log --oneline
# With graph
git log --oneline --graph --all
# Last 5 commits
git log -5
# Commits by author
git log --author="John"
# Commits in date range
git log --since="2 weeks ago"
# Search commit messages
git log --grep="keyword"
# Search code changes
git log -S "function_name"
# Show file history
git log --follow -- path/to/file
# 1. Create correct branch from current state
git branch feature/correct-branch
# 2. Reset current branch
git reset --hard HEAD~1
# 3. Switch to correct branch
git checkout feature/correct-branch
# If not pushed yet
git reset --hard HEAD~1
# If already pushed (creates revert commit)
git revert -m 1 <merge-commit-hash>
# Find lost commit
git reflog
# Create branch from lost commit
git checkout -b recovered-branch <commit-hash>
# Add upstream remote
git remote add upstream https://github.com/original/repo.git
# Fetch upstream
git fetch upstream
# Merge upstream main
git checkout main
git merge upstream/main
# Push to your fork
git push origin main
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.lg 'log --oneline --graph --all'
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
Weekly Installs
1
Repository
GitHub Stars
3
First Seen
1 day ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
mcpjam1
claude-code1
junie1
windsurf1
zencoder1
crush1
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
111,800 周安装