git - 从历史记录中删除分支
问题描述
我有这种情况:
- 主要分支是
Develop
Develop
我从被调用创建了一个新分支Task1
- 我进行了更改
Task1
并提交了 - 我做了进一步的修改
Task1
并再次提交 - 事实证明,不应调用该任务
Task1
(出于某些原因)。Task2
必须创建一个名为的子任务 Task2
是从Task1
分支创建的(在Task2
需要的更改中进行了Task1
)- 在
Task2
中,我做了进一步的代码更改
现在我想Task1
从历史记录中删除分支
所做的更改Task1
必须保留在Task2
现在是:
开发- Task1 : (commit1, commit2) - Task2 : (commit1, commit2 等)
它应该如下所示:
开发-任务 2:( commit1、commit2、commit3 等)
编辑:
Task1
必须删除提交,但所做的更改仍保留在Task2
解决方案
分支只是指向提交的指针,所以如果Task2
在前面或在同一级别Task1
,您可以删除Task1
:
# delete the branch locally
git branch -d Task1
# delete the branch remotely (if you remote is not called origin, change that with your remote name)
git push origin :Task1
可从中访问的提交Task1
仍将位于Task2
.
推荐阅读
- c# - 每次迭代或循环浏览文档列表时,如何创建新的 PDF 文件?
- c - 与位置无关的可执行文件:什么是“主要可执行二进制文件”?
- jquery - 在 php 字符串中使用替换函数
- com - 如何让我的 WiX 产品脚本正确安装我的活动 x 控件?
- python - 一种用组有效地替换数组元素的算法
- angular - Nginx 重新加载 Angular 应用程序
- html - 如果空单元格更改行颜色,则html css表
- azure-devops - 如何使发布管道期间生成的文件可访问?
- python - 自动决定从python中的相关矩阵中删除哪个特征
- python - 将 var 值从 HTML 传递到 python