Git | Feature分支操作

基本概念

原则
  • 安全隔离 ------ 每通过分支隔离高风险变更
  • 灵活放弃 ------ 每-D 参数提供紧急撤销能力
  • 流程规范 ------ 每个功能开发 → 测试合并 → 清理分支
原理
创建 feature 分支并在其上开发
  • dev 分支上创建开发分支 feature-newFunc 开发新功能 newFunc
开发完成并安全删除
  • 开发完成后,将其合并到 dev 分支,安全删除 feature-newFunc 分支
开发废弃并强制删除
  • 开发中途取消开发,强制删除 feature-newFunc 分支

Feature 分支使用

相关指令
  • git branch -d ------ 安全删除已合并分支(功能通过后)
  • git branch -D ------ 强制删除未合并分支(功能需废弃)
场景一:在 dev 分支开发 newFunc 功能,开发完成并合并
  1. 创建 feature 开发分支

    sh 复制代码
    $ git switch -c feature-newFunc  			# 从当前分支创建并切换到新分支
  2. 开发并提交

    sh 复制代码
    # 开发代码...
    $ git add .
    $ git commit -m "new function 101"
  3. 合并到主分支并安全 删除 feature 开发分支

    sh 复制代码
    $ git switch dev          				# 切回主分支
    $ git merge feature-newFunc   			# 合并功能分支
    sh 复制代码
    $ git branch -d feature-newFunc  			# 安全删除已合并分支 -d
场景二:正在 dev 分支开发 newFunc 功能,开发中途废弃
  1. 创建 feature 开发分支(同上)

  2. 开发并提交(同上)

  3. 中途废弃并强制 删除 feature 开发分支

    sh 复制代码
    git branch -D feature-newFunc  			# 强制删除未合并分支 -D

相关推荐
Codeking__1 天前
Redis——基本通用命令
redis·git·github
独自破碎E1 天前
下载 GitHub 仓库「单个文件夹」的方法
github
大厂技术总监下海1 天前
“Today I Learned”(TIL):一种比写博客更可持续的知识沉淀习惯
大数据·开源·github
Dontla1 天前
Git error: fatal: detected dubious ownership in repository at xxx
git
论迹2 天前
【Git】-- 多人协作
git·ubuntu
掘金安东尼2 天前
⏰前端周刊第 448 期(2026年1月4日-1月10日)
前端·面试·github
roamingcode2 天前
从混沌到秩序:Git Diff 结构化报告的 Claude Code Skill 实践
人工智能·git·agent·skill·claude code·领域知识包·ai经验复用
掘金安东尼2 天前
向大家介绍《开发者博主联盟》🚀
前端·程序员·github
ss2732 天前
idea中git更新项目:将传入更改合并到当前分支,在传入更改上变基当前分支
java·git·intellij-idea
hopsky2 天前
好用!Git 同时开发多个分支
git