git - Git Rebase 已合并分支
问题描述
我从主develop
分支创建了功能分支,称为my-feature
另一个开发人员创建的另一个功能分支another-feature
。
我们都在不同的文件中进行更改
另一个开发人员已经创建了 PR,但尚未合并到开发中。但是,我需要他对我的分支进行更改,所以我git merge another-feature
对我的功能分支进行了更改并创建了拉取请求。
但是,主要问题是现在,我可以看到another-feature
分支对我的拉取请求的更改my-feature
。那么,我该如何重新设置呢?我不想显示来自另一个分支的更改。
我检查了另一篇文章,但其中一些对我来说不太容易理解。
任何帮助将不胜感激。
编辑:
git log
显示如下。(目标分支是develop
)
commit: f0fdfddsdsde
Author: Me (As my last commit before creating PR)
Date: blah blah
commit message....
commit: a4dsdsdssdds
Author: Another developer (whose changes I merged)
Date: blah blah
commit message....
rest of another commits ....
git log ––all ––decorate ––oneline ––graph
f0acaed (HEAD -> feature/my-feature, origin/my-feature) commit message..
a4f4dab (origin/another-feature, feature/another-feature) commit message..
* db30503 (origin/HEAD, origin/develop, develop) merge pull request from another branch
blah blah blah
解决方案
another-feature
除非合并,否则更改将在您的 PR 上可见。
如果您只是不想在审查时看到 PR 中的这些更改,只需在审查期间更改基本分支(如果您使用的版本控制系统允许)。
另一个解决方案(我更喜欢)是重新设置您的分支,another-feature
而不是合并它们。
在这种情况下,当另一个特性被合并时,你就不会那么头疼了,而且在审查时,你将能够只审查你推送的提交(大多数系统允许你在审查时选择提交集)。
更新:( 对于上面提到的第二种方法)
为了跳转到 的原始状态my-feature
,您需要使用reflog
.
这是如何做到这一点的。
- 通过键入确保没有待处理的更改
git status
- 键入
git reflog
,您会看到类似这样的内容: 您可以在此处看到头部引用的历史记录。只需找到合并之前的提交(在图片中它是HEAD@{1}
带有 commit hash 的提交e919ec6
)。 - 现在只需使用以下命令签出该提交:(
git checkout HASH_HERE
例如git checkout e919ec6
) - 现在只需从该提交创建一个分支(为方便起见)
checkout -b my-feature.ORIGINAL
现在,my-feature.ORIGINAL
在合并之前包含您的分支状态,并且您在该分支上。
为了进行变基而不是合并,请按照下列步骤操作:
- 备份您的分支(再次只是为了方便)
git branch my-feature.BKP
- 使用另一个功能重新设置分支
git rebase another-feature
- 重命名旧的坏分支(为方便起见)
git rename my-feature my-feature.BAD
- 将您当前的分支名称从 my-feature.ORIGINAL 更改为 my-feature (以匹配远程分支名称)
git rename my-feature.ORIGINAL my-feature
- 现在您可以强制将您的分支推送到您的远程分支,并且 PR 将被更新。
推荐阅读
- python - 堆栈,枢轴或其他东西?
- python - 使用 Python 将黑白图像转换为列表列表 (0, 1)
- big-o - When are Big O notations true?
- python - 此代码正在运行,但现在我从 __getattribute__ 中的计数器收到递归错误
- python - Numpy 数组运算符返回全白图像
- reactjs - 如何在一个请求中通过 axios api 将两个不同的值发送到我的后端?
- python - Python:IDE中的代码是正确的,但在作业中是不正确的
- ios - 使用 buildmode=c-archive 为 armv7s 编译
- corda - Corda io.bluebank.braid 与 Corda Enterprise 有问题
- flutter - 如何打印实例?