feat: 重构工作流体系,将命令模式迁移为技能文档
This commit is contained in:
@@ -7,6 +7,13 @@ description: Git workflow best practices with commit conventions, tagging, and c
|
||||
|
||||
You are an expert in Git version control and repository management.
|
||||
|
||||
## 功能文档
|
||||
|
||||
| 文档 | 说明 |
|
||||
|------|------|
|
||||
| [Commit Workflow](./commit-workflow.md) | 提交暂存文件,自动生成提交信息并创建版本标签 |
|
||||
| [Push Workflow](./push-workflow.md) | 提交并推送到远程仓库的完整工作流 |
|
||||
|
||||
## Core Principles
|
||||
|
||||
1. **Default Main Branch**: Use `main` as the primary branch (not `master`)
|
||||
|
||||
163
skill/git/commit-workflow.md
Normal file
163
skill/git/commit-workflow.md
Normal file
@@ -0,0 +1,163 @@
|
||||
# Git Commit Workflow
|
||||
|
||||
提交暂存文件,自动生成提交信息并创建版本标签的完整工作流。
|
||||
|
||||
## 概述
|
||||
|
||||
此工作流用于:
|
||||
- 自动分析暂存区变更
|
||||
- 根据 Conventional Commits 规范生成提交信息
|
||||
- 检测项目类型并更新版本号
|
||||
- 创建语义化版本标签
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### 步骤 1: 检查暂存区
|
||||
|
||||
```bash
|
||||
git diff --cached --name-only
|
||||
```
|
||||
|
||||
- 如果暂存区为空,通知用户并停止
|
||||
- 如果有文件,继续下一步
|
||||
|
||||
### 步骤 2: 收集信息(并行执行)
|
||||
|
||||
```bash
|
||||
# 并行执行以下命令
|
||||
git status
|
||||
git diff --cached
|
||||
git log --oneline -10
|
||||
git tag --list | sort -V | tail -5
|
||||
```
|
||||
|
||||
同时检查 `AGENTS.md` 文件获取:
|
||||
- 仓库类型(polyrepo/monorepo)
|
||||
- 版本规则
|
||||
- 项目结构信息
|
||||
|
||||
### 步骤 3: 检测仓库类型
|
||||
|
||||
**Polyrepo(单仓库)**
|
||||
- Tag 格式:`<version>`(如 `1.2.0`)
|
||||
|
||||
**Monorepo(多项目)**
|
||||
- Tag 格式:`<subproject>-<version>`(如 `ios-1.2.0`)
|
||||
- 检测特征:`packages/`、`apps/`、`services/` 目录
|
||||
|
||||
### 步骤 4: 检测项目类型和版本
|
||||
|
||||
| 项目类型 | 版本文件 | 版本字段 |
|
||||
|---------|---------|---------|
|
||||
| iOS | `*.xcodeproj/project.pbxproj` | `MARKETING_VERSION` |
|
||||
| Node.js | `package.json` | `version` |
|
||||
| Android (Groovy) | `app/build.gradle` | `versionName` |
|
||||
| Android (Kotlin) | `app/build.gradle.kts` | `versionName` |
|
||||
| Go | Git tag only | - |
|
||||
| Python | `pyproject.toml` / `setup.py` | `version` |
|
||||
| Rust | `Cargo.toml` | `version` |
|
||||
|
||||
### 步骤 5: 生成提交信息
|
||||
|
||||
遵循 Conventional Commits 格式:
|
||||
|
||||
```
|
||||
<type>(<scope>): <subject>
|
||||
```
|
||||
|
||||
**提交类型**:
|
||||
|
||||
| Type | 描述 | 版本影响 |
|
||||
|------|------|---------|
|
||||
| `feat` | 新功能 | minor +1 |
|
||||
| `fix` | Bug 修复 | patch +1 |
|
||||
| `perf` | 性能优化 | patch +1 |
|
||||
| `BREAKING CHANGE` | 破坏性变更 | major +1 |
|
||||
| `docs` | 文档更新 | 无 |
|
||||
| `style` | 代码格式 | 无 |
|
||||
| `refactor` | 重构 | 无 |
|
||||
| `test` | 测试 | 无 |
|
||||
| `chore` | 维护任务 | 无 |
|
||||
| `ci` | CI/CD 变更 | 无 |
|
||||
| `build` | 构建配置 | 无 |
|
||||
|
||||
**提交语言**:
|
||||
- macOS/Linux:使用中文
|
||||
- Windows:使用英文(避免编码问题)
|
||||
|
||||
**Monorepo Scope**:
|
||||
- 单项目变更:`feat(ios): 添加上传功能`
|
||||
- 多项目变更:`chore: 更新共享依赖`
|
||||
|
||||
### 步骤 6: 确定新版本号
|
||||
|
||||
根据提交类型计算新版本:
|
||||
|
||||
**版本递增规则**:
|
||||
- `feat`:minor +1(如 `1.2.0` → `1.3.0`)
|
||||
- `fix`/`perf`:patch +1(如 `1.2.3` → `1.2.4`)
|
||||
- Breaking change:major +1(如 `1.2.3` → `2.0.0`)
|
||||
|
||||
**不更新版本**:
|
||||
- `docs`、`test`、`refactor`、`style`、`build`、`ci`、`chore`
|
||||
|
||||
### 步骤 7: 更新版本文件并暂存
|
||||
|
||||
如果需要更新版本(步骤 6 确定了新版本号):
|
||||
|
||||
1. **更新版本文件**:将版本号写入对应的版本文件
|
||||
2. **添加到暂存区**:
|
||||
```bash
|
||||
git add <version-file>
|
||||
```
|
||||
3. **验证暂存**:
|
||||
```bash
|
||||
git diff --cached --name-only
|
||||
```
|
||||
确认版本文件已在暂存区
|
||||
|
||||
### 步骤 8: 执行提交
|
||||
|
||||
```bash
|
||||
git commit -m "<commit-message>"
|
||||
```
|
||||
|
||||
### 步骤 9: 创建版本标签
|
||||
|
||||
仅在版本更新时创建(除非用户指定 "skip tag"):
|
||||
|
||||
**Polyrepo**:
|
||||
```bash
|
||||
git tag -a "1.2.0" -m "<commit-message>"
|
||||
```
|
||||
|
||||
**Monorepo**:
|
||||
```bash
|
||||
git tag -a "ios-1.2.0" -m "<commit-message>"
|
||||
```
|
||||
|
||||
## 选项
|
||||
|
||||
- `skip tag` / `skip`:跳过标签创建
|
||||
|
||||
## 输出格式
|
||||
|
||||
```
|
||||
✓ 提交成功
|
||||
|
||||
提交信息:[commit message]
|
||||
版本标签:[tag](如果创建了)
|
||||
|
||||
要推送到远程仓库,请运行:/git-push
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 此命令**不会推送**到远程,使用 `/git-push` 推送
|
||||
- 暂存区为空时会提示用户先 `git add`
|
||||
- 标签注释使用与提交相同的消息内容
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Git Workflow Best Practices](./SKILL.md)
|
||||
- [Push Workflow](./push-workflow.md)
|
||||
107
skill/git/push-workflow.md
Normal file
107
skill/git/push-workflow.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Git Push Workflow
|
||||
|
||||
提交暂存文件,创建版本标签并推送到远程仓库的完整工作流。
|
||||
|
||||
## 概述
|
||||
|
||||
此工作流是 **All-in-One** 命令,组合了:
|
||||
- `/git-commit` 的所有功能
|
||||
- 推送提交到远程
|
||||
- 推送标签到远程
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### 步骤 1-9: 与 Commit Workflow 相同
|
||||
|
||||
参考 [Commit Workflow](./commit-workflow.md):
|
||||
|
||||
1. 检查暂存区(不能为空)
|
||||
2. 收集变更信息和仓库状态
|
||||
3. 检测仓库类型(polyrepo/monorepo)
|
||||
4. 检测项目类型和版本
|
||||
5. 生成提交信息(Conventional Commits,中文)
|
||||
6. 确定新版本号
|
||||
7. 更新版本文件并添加到暂存区
|
||||
8. 执行提交
|
||||
9. 创建版本标签
|
||||
|
||||
### 步骤 10: 推送提交到远程
|
||||
|
||||
```bash
|
||||
git push origin $(git branch --show-current)
|
||||
```
|
||||
|
||||
### 步骤 11: 推送标签到远程
|
||||
|
||||
仅在创建了标签时执行:
|
||||
|
||||
**Polyrepo**:
|
||||
```bash
|
||||
git push origin <version>
|
||||
```
|
||||
|
||||
**Monorepo**:
|
||||
```bash
|
||||
git push origin <subproject>-<version>
|
||||
```
|
||||
|
||||
## 选项
|
||||
|
||||
- `skip tag` / `skip`:跳过标签创建
|
||||
|
||||
## 输出格式
|
||||
|
||||
```
|
||||
✓ 提交并推送成功
|
||||
|
||||
分支:[branch]
|
||||
提交信息:[commit message]
|
||||
版本标签:[tag](如果创建了)
|
||||
|
||||
已推送到远程仓库:origin
|
||||
- 提交:[commit hash]
|
||||
- 标签:[tag]
|
||||
```
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 暂存区为空
|
||||
|
||||
```
|
||||
暂存区为空,请先使用 `git add` 添加文件。
|
||||
```
|
||||
|
||||
### 推送失败
|
||||
|
||||
```
|
||||
❌ 推送失败:[error message]
|
||||
|
||||
可能的解决方案:
|
||||
1. 先拉取远程变更:git pull origin <branch>
|
||||
2. 检查网络连接
|
||||
3. 检查远程仓库权限
|
||||
```
|
||||
|
||||
### 标签已存在
|
||||
|
||||
```
|
||||
❌ 标签推送失败:tag already exists
|
||||
|
||||
解决方案:
|
||||
1. 删除本地标签:git tag -d <tag>
|
||||
2. 更新版本号后重新提交
|
||||
```
|
||||
|
||||
## 使用场景
|
||||
|
||||
| 场景 | 推荐命令 |
|
||||
|------|---------|
|
||||
| 本地提交,稍后审查 | `/git-commit` |
|
||||
| 提交并立即推送 | `/git-push` |
|
||||
| 仅推送已有提交 | `git push origin <branch>` |
|
||||
| 仅推送标签 | `git push origin <tag>` |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Git Workflow Best Practices](./SKILL.md)
|
||||
- [Commit Workflow](./commit-workflow.md)
|
||||
@@ -1,663 +0,0 @@
|
||||
# Git Quick Reference
|
||||
|
||||
Quick reference guide for common Git operations.
|
||||
|
||||
## File Changes and Status
|
||||
|
||||
### View Changed Files
|
||||
|
||||
```bash
|
||||
# Show working directory status
|
||||
git status
|
||||
|
||||
# Show short status
|
||||
git status -s
|
||||
|
||||
# List changed files only (unstaged)
|
||||
git diff --name-only
|
||||
|
||||
# List changed files only (staged)
|
||||
git diff --cached --name-only
|
||||
# or
|
||||
git diff --staged --name-only
|
||||
|
||||
# Show file change statistics
|
||||
git diff --stat
|
||||
git diff --cached --stat
|
||||
```
|
||||
|
||||
### View Detailed Changes
|
||||
|
||||
```bash
|
||||
# View unstaged changes
|
||||
git diff
|
||||
|
||||
# View staged changes
|
||||
git diff --cached
|
||||
# or
|
||||
git diff --staged
|
||||
|
||||
# View specific file changes
|
||||
git diff <file-path>
|
||||
git diff --cached <file-path>
|
||||
|
||||
# View changes between commits
|
||||
git diff <commit1>..<commit2>
|
||||
git diff HEAD~1..HEAD
|
||||
|
||||
# View changes between branches
|
||||
git diff main..feature-branch
|
||||
```
|
||||
|
||||
## Staging and Committing
|
||||
|
||||
### Add Files to Staging
|
||||
|
||||
```bash
|
||||
# Add specific file
|
||||
git add <file-path>
|
||||
|
||||
# Add all files in directory
|
||||
git add .
|
||||
|
||||
# Add all files in repository
|
||||
git add -A
|
||||
|
||||
# Add files interactively
|
||||
git add -p
|
||||
|
||||
# Add only modified files (not new files)
|
||||
git add -u
|
||||
```
|
||||
|
||||
### Check Staging Area
|
||||
|
||||
```bash
|
||||
# List files in staging area
|
||||
git diff --cached --name-only
|
||||
|
||||
# Show detailed staged changes
|
||||
git diff --cached
|
||||
```
|
||||
|
||||
### Commit Changes
|
||||
|
||||
```bash
|
||||
# Simple commit
|
||||
git commit -m "feat: add user authentication"
|
||||
|
||||
# Multi-line commit (macOS/Linux)
|
||||
git commit -m "$(cat <<'EOF'
|
||||
feat: add user authentication
|
||||
|
||||
- Add OAuth2 support
|
||||
- Implement JWT tokens
|
||||
- Add login/logout endpoints
|
||||
EOF
|
||||
)"
|
||||
|
||||
# Multi-line commit (Windows)
|
||||
git commit -m "feat: add user authentication" \
|
||||
-m "" \
|
||||
-m "- Add OAuth2 support" \
|
||||
-m "- Implement JWT tokens" \
|
||||
-m "- Add login/logout endpoints"
|
||||
|
||||
# Commit with automatic staging
|
||||
git commit -am "fix: resolve issue"
|
||||
|
||||
# Amend last commit (before push only!)
|
||||
git commit --amend -m "new message"
|
||||
```
|
||||
|
||||
## Tag Management
|
||||
|
||||
### Create Tags
|
||||
|
||||
```bash
|
||||
# Create annotated tag
|
||||
git tag -a "1.2.0" -m "feat: add new feature"
|
||||
|
||||
# Create lightweight tag
|
||||
git tag "1.2.0"
|
||||
|
||||
# Create tag with multi-line message
|
||||
git tag -a "1.2.1" \
|
||||
-m "fix: resolve connection issue" \
|
||||
-m "" \
|
||||
-m "- Increase timeout to 30s" \
|
||||
-m "- Add retry mechanism"
|
||||
|
||||
# Create tag for specific commit
|
||||
git tag -a "1.2.0" <commit-hash> -m "message"
|
||||
|
||||
# Monorepo tag
|
||||
git tag -a "ios-1.2.0" -m "feat(ios): add feature"
|
||||
```
|
||||
|
||||
### List Tags
|
||||
|
||||
```bash
|
||||
# List all tags
|
||||
git tag
|
||||
|
||||
# List tags with pattern
|
||||
git tag -l "v1.*"
|
||||
|
||||
# List recent tags (sorted)
|
||||
git tag --list | sort -V | tail -5
|
||||
|
||||
# Show tag details
|
||||
git show <tag-name>
|
||||
```
|
||||
|
||||
### Push Tags
|
||||
|
||||
```bash
|
||||
# Push single tag
|
||||
git push origin <tag-name>
|
||||
|
||||
# Push all tags
|
||||
git push --tags
|
||||
# or
|
||||
git push origin --tags
|
||||
|
||||
# Push commit and tag together
|
||||
git push origin main && git push origin 1.2.0
|
||||
```
|
||||
|
||||
### Delete Tags
|
||||
|
||||
```bash
|
||||
# Delete local tag
|
||||
git tag -d <tag-name>
|
||||
|
||||
# Delete remote tag
|
||||
git push origin --delete <tag-name>
|
||||
# or
|
||||
git push origin :refs/tags/<tag-name>
|
||||
|
||||
# Delete multiple tags
|
||||
git tag -d tag1 tag2 tag3
|
||||
```
|
||||
|
||||
## Branch Operations
|
||||
|
||||
### View Branches
|
||||
|
||||
```bash
|
||||
# Show current branch
|
||||
git branch --show-current
|
||||
|
||||
# List local branches
|
||||
git branch
|
||||
|
||||
# List all branches (local + remote)
|
||||
git branch -a
|
||||
|
||||
# List remote branches only
|
||||
git branch -r
|
||||
|
||||
# Show branch with last commit
|
||||
git branch -v
|
||||
```
|
||||
|
||||
### Create and Switch Branches
|
||||
|
||||
```bash
|
||||
# Create new branch
|
||||
git branch <branch-name>
|
||||
|
||||
# Create and switch to new branch (old way)
|
||||
git checkout -b <branch-name>
|
||||
|
||||
# Create and switch to new branch (modern)
|
||||
git switch -c <branch-name>
|
||||
|
||||
# Switch to existing branch (old way)
|
||||
git checkout <branch-name>
|
||||
|
||||
# Switch to existing branch (modern)
|
||||
git switch <branch-name>
|
||||
|
||||
# Switch to previous branch
|
||||
git switch -
|
||||
```
|
||||
|
||||
### Delete Branches
|
||||
|
||||
```bash
|
||||
# Delete local branch (safe)
|
||||
git branch -d <branch-name>
|
||||
|
||||
# Delete local branch (force)
|
||||
git branch -D <branch-name>
|
||||
|
||||
# Delete remote branch
|
||||
git push origin --delete <branch-name>
|
||||
# or
|
||||
git push origin :<branch-name>
|
||||
```
|
||||
|
||||
## Pushing and Pulling
|
||||
|
||||
### Push Changes
|
||||
|
||||
```bash
|
||||
# Push current branch
|
||||
git push
|
||||
|
||||
# Push to specific remote and branch
|
||||
git push origin main
|
||||
|
||||
# Push current branch to remote
|
||||
git push origin $(git branch --show-current)
|
||||
|
||||
# Push with upstream tracking
|
||||
git push -u origin <branch-name>
|
||||
|
||||
# Push all branches
|
||||
git push --all
|
||||
|
||||
# Push all tags
|
||||
git push --tags
|
||||
|
||||
# Force push (dangerous!)
|
||||
git push --force
|
||||
# Better: force push with lease
|
||||
git push --force-with-lease
|
||||
```
|
||||
|
||||
### Pull Changes
|
||||
|
||||
```bash
|
||||
# Pull from tracked remote
|
||||
git pull
|
||||
|
||||
# Pull from specific remote and branch
|
||||
git pull origin main
|
||||
|
||||
# Pull with rebase
|
||||
git pull --rebase
|
||||
|
||||
# Pull and prune deleted remote branches
|
||||
git pull --prune
|
||||
```
|
||||
|
||||
### Fetch Changes
|
||||
|
||||
```bash
|
||||
# Fetch from all remotes
|
||||
git fetch
|
||||
|
||||
# Fetch from specific remote
|
||||
git fetch origin
|
||||
|
||||
# Fetch and prune deleted remote branches
|
||||
git fetch --prune
|
||||
|
||||
# Fetch all branches and tags
|
||||
git fetch --all --tags
|
||||
```
|
||||
|
||||
## History and Logs
|
||||
|
||||
### View Commit History
|
||||
|
||||
```bash
|
||||
# View recent commits
|
||||
git log
|
||||
|
||||
# View compact history
|
||||
git log --oneline
|
||||
|
||||
# View recent 10 commits
|
||||
git log --oneline -10
|
||||
|
||||
# View history with graph
|
||||
git log --graph --oneline --all
|
||||
|
||||
# View history with stats
|
||||
git log --stat
|
||||
|
||||
# View history with patches
|
||||
git log -p
|
||||
```
|
||||
|
||||
### Search History
|
||||
|
||||
```bash
|
||||
# Search commits by message
|
||||
git log --grep="feature"
|
||||
|
||||
# Search by author
|
||||
git log --author="John"
|
||||
|
||||
# Search by date
|
||||
git log --since="2024-01-01"
|
||||
git log --after="2 weeks ago"
|
||||
git log --before="yesterday"
|
||||
|
||||
# Search by file
|
||||
git log -- <file-path>
|
||||
|
||||
# Search code changes
|
||||
git log -S "function_name"
|
||||
```
|
||||
|
||||
### View Commit Details
|
||||
|
||||
```bash
|
||||
# Show specific commit
|
||||
git show <commit-hash>
|
||||
|
||||
# Show specific tag
|
||||
git show <tag-name>
|
||||
|
||||
# Show HEAD commit
|
||||
git show HEAD
|
||||
|
||||
# Show previous commit
|
||||
git show HEAD~1
|
||||
git show HEAD^
|
||||
```
|
||||
|
||||
## Undoing Changes
|
||||
|
||||
### Discard Changes
|
||||
|
||||
```bash
|
||||
# Discard unstaged changes in file
|
||||
git checkout -- <file-path>
|
||||
# or (modern)
|
||||
git restore <file-path>
|
||||
|
||||
# Discard all unstaged changes
|
||||
git checkout -- .
|
||||
# or (modern)
|
||||
git restore .
|
||||
|
||||
# Unstage file (keep changes)
|
||||
git reset HEAD <file-path>
|
||||
# or (modern)
|
||||
git restore --staged <file-path>
|
||||
|
||||
# Unstage all files
|
||||
git reset HEAD
|
||||
# or (modern)
|
||||
git restore --staged .
|
||||
```
|
||||
|
||||
### Reset Commits
|
||||
|
||||
```bash
|
||||
# Undo last commit, keep changes staged
|
||||
git reset --soft HEAD~1
|
||||
|
||||
# Undo last commit, keep changes unstaged
|
||||
git reset HEAD~1
|
||||
# or
|
||||
git reset --mixed HEAD~1
|
||||
|
||||
# Undo last commit, discard changes (dangerous!)
|
||||
git reset --hard HEAD~1
|
||||
|
||||
# Reset to specific commit
|
||||
git reset --hard <commit-hash>
|
||||
```
|
||||
|
||||
### Revert Commits
|
||||
|
||||
```bash
|
||||
# Create new commit that undoes a commit
|
||||
git revert <commit-hash>
|
||||
|
||||
# Revert without committing
|
||||
git revert -n <commit-hash>
|
||||
|
||||
# Revert multiple commits
|
||||
git revert <commit1>..<commit2>
|
||||
```
|
||||
|
||||
## Stash Operations
|
||||
|
||||
### Save Changes
|
||||
|
||||
```bash
|
||||
# Stash current changes
|
||||
git stash
|
||||
|
||||
# Stash with message
|
||||
git stash save "work in progress"
|
||||
|
||||
# Stash including untracked files
|
||||
git stash -u
|
||||
|
||||
# Stash including untracked and ignored files
|
||||
git stash -a
|
||||
```
|
||||
|
||||
### Apply Stash
|
||||
|
||||
```bash
|
||||
# Apply most recent stash
|
||||
git stash apply
|
||||
|
||||
# Apply and remove from stash list
|
||||
git stash pop
|
||||
|
||||
# Apply specific stash
|
||||
git stash apply stash@{2}
|
||||
```
|
||||
|
||||
### Manage Stash
|
||||
|
||||
```bash
|
||||
# List all stashes
|
||||
git stash list
|
||||
|
||||
# Show stash changes
|
||||
git stash show
|
||||
git stash show -p
|
||||
|
||||
# Drop specific stash
|
||||
git stash drop stash@{1}
|
||||
|
||||
# Clear all stashes
|
||||
git stash clear
|
||||
```
|
||||
|
||||
## Remote Operations
|
||||
|
||||
### View Remotes
|
||||
|
||||
```bash
|
||||
# List remotes
|
||||
git remote
|
||||
|
||||
# List remotes with URLs
|
||||
git remote -v
|
||||
|
||||
# Show remote details
|
||||
git remote show origin
|
||||
```
|
||||
|
||||
### Manage Remotes
|
||||
|
||||
```bash
|
||||
# Add remote
|
||||
git remote add <name> <url>
|
||||
|
||||
# Remove remote
|
||||
git remote remove <name>
|
||||
|
||||
# Rename remote
|
||||
git remote rename <old-name> <new-name>
|
||||
|
||||
# Change remote URL
|
||||
git remote set-url <name> <new-url>
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### View Configuration
|
||||
|
||||
```bash
|
||||
# View all config
|
||||
git config --list
|
||||
|
||||
# View global config
|
||||
git config --global --list
|
||||
|
||||
# View local config
|
||||
git config --local --list
|
||||
|
||||
# View specific config
|
||||
git config user.name
|
||||
git config user.email
|
||||
```
|
||||
|
||||
### Set Configuration
|
||||
|
||||
```bash
|
||||
# Set user name
|
||||
git config --global user.name "Your Name"
|
||||
|
||||
# Set user email
|
||||
git config --global user.email "your.email@example.com"
|
||||
|
||||
# Set default branch name
|
||||
git config --global init.defaultBranch main
|
||||
|
||||
# Set default editor
|
||||
git config --global core.editor "code --wait"
|
||||
|
||||
# Set credential helper
|
||||
git config --global credential.helper store
|
||||
```
|
||||
|
||||
## Workflow Examples
|
||||
|
||||
### Standard Commit and Tag Workflow
|
||||
|
||||
```bash
|
||||
# 1. Check status
|
||||
git status
|
||||
git diff --cached --name-only
|
||||
|
||||
# 2. Stage changes
|
||||
git add .
|
||||
|
||||
# 3. Commit
|
||||
git commit -m "feat: add user authentication"
|
||||
|
||||
# 4. Create tag
|
||||
git tag -a "1.2.0" -m "feat: add user authentication"
|
||||
|
||||
# 5. Push commit and tag
|
||||
git push origin main
|
||||
git push origin 1.2.0
|
||||
```
|
||||
|
||||
### Complete Staging to Push Workflow
|
||||
|
||||
```bash
|
||||
# Check what files changed
|
||||
git status
|
||||
|
||||
# View changes
|
||||
git diff
|
||||
|
||||
# Stage specific files
|
||||
git add src/auth.js src/api.js
|
||||
|
||||
# Verify staging
|
||||
git diff --cached --name-only
|
||||
|
||||
# Commit with message
|
||||
git commit -m "feat: implement OAuth2 authentication"
|
||||
|
||||
# Push to remote
|
||||
git push origin main
|
||||
```
|
||||
|
||||
### Push All Tags Workflow
|
||||
|
||||
```bash
|
||||
# List local tags
|
||||
git tag
|
||||
|
||||
# View recent tags
|
||||
git tag --list | sort -V | tail -5
|
||||
|
||||
# Push all tags to remote
|
||||
git push --tags
|
||||
|
||||
# Verify tags on remote
|
||||
git ls-remote --tags origin
|
||||
```
|
||||
|
||||
### Quick Status Check
|
||||
|
||||
```bash
|
||||
# Full status
|
||||
git status
|
||||
|
||||
# Changed files only
|
||||
git diff --name-only
|
||||
git diff --cached --name-only
|
||||
|
||||
# Recent commits and tags
|
||||
git log --oneline -5
|
||||
git tag --list | sort -V | tail -5
|
||||
|
||||
# Current branch
|
||||
git branch --show-current
|
||||
```
|
||||
|
||||
## Tips and Tricks
|
||||
|
||||
### Aliases
|
||||
|
||||
Add to `~/.gitconfig`:
|
||||
|
||||
```ini
|
||||
[alias]
|
||||
st = status
|
||||
co = checkout
|
||||
br = branch
|
||||
ci = commit
|
||||
unstage = restore --staged
|
||||
last = log -1 HEAD
|
||||
lg = log --graph --oneline --all
|
||||
tags = tag -l --sort=-v:refname
|
||||
```
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
git st
|
||||
git co main
|
||||
git lg
|
||||
```
|
||||
|
||||
### Useful One-Liners
|
||||
|
||||
```bash
|
||||
# Delete all merged branches
|
||||
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
|
||||
|
||||
# View file in specific commit
|
||||
git show <commit>:<file-path>
|
||||
|
||||
# Count commits by author
|
||||
git shortlog -sn
|
||||
|
||||
# Find when a line was changed
|
||||
git blame <file-path>
|
||||
|
||||
# Show what changed in each commit for a file
|
||||
git log -p <file-path>
|
||||
|
||||
# List files in a commit
|
||||
git diff-tree --no-commit-id --name-only -r <commit>
|
||||
```
|
||||
Reference in New Issue
Block a user