合并git分支而不移动分支指针 [英] Merge git branch without moving branch pointer

查看:168
本文介绍了合并git分支而不移动分支指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种解决方案,将功能分支应用于git中的开发分支,而无需实际移动分支指针。基本上,我想创建一个单独的功能分支,并确保它以某种方式指向原始分支(在日志中提及可能就足够了)。



我知道堆栈的git应该提供类似的东西,尽管这会为标准工作流程引入新的命令,我宁愿避免这些命令。



我正在尝试的实现是某种功能管理,它允许我们应用/删除整个功能,同时保持修补程序分支本身的可见性。如果我合并分支,大多数尝试区分变化的命令都不会做我想做的事情,因为分支已经合并到开发中。

我不能真正遵循上游 - 有时会发生并发更改,通过获取新标签并仅重新应用所需的功能,而不是解决冲突和恢复冗余功能,更易于纠正 - 因此无法实现这种工作方式。另一方面,我确实希望看到更改,以便我可以重新修改它以匹配新版本,或者稍后再提交上游。 解决方案

据我所知,你可以使用git rebase -i来实现你的目标。
下面是你想要实现的场景......

  A  -  B  -  C(develop)

\ D - E - F(功能)

您可以将DEF组合为一个名为G
的单个提交,最终结果将为

  A  -  B-- C  -  G(开发)
\
\D - E - F(功能)

G是一个单独的提交,它具有DEF中的所有功能,您可以轻松地从develop分支中取出它。




所以为了处理这个手术,你可以做....

git checkout feature_branch

code>



创建一个临时分支...



git checkout -b temp



git rebase -i develop_branch



,交互式编辑器将被提示出...
标记提交D和E作为压扁,保留最后一行(提交)作为最后一次提交
保存并退出



然后是一个commi (G)将发放到您的开发分支。

  A  -  B  -  C(develop) -  G(temp) 
\
\D - E - F(功能)

将你的开发重置到提交G并删除临时分支。

  git checkout develop_branch 
git reset - 硬<提交G的shaSum>
git -D temp

就这样!


I'm looking for a solution to apply a feature branch to the development branch in git without actually moving the branch pointer. Essentially, I'd like to create a single commit off of the feature branch and make sure it's pointing at the originating branch somehow (mention in the log might be enough).

I know that stacked git should offer something like that, although that would introduce new commands to the standard workflow which I'd rather avoid.

What I'm trying to achieve is some sort of feature management which allows us to apply / remove whole features, while keeping the visibility of the patch branch itself. If I do merge the branch, most commands trying to diff the change will not do what I want because the branch is already merged into develop.

I cannot really follow the upstream - sometimes there are concurrent changes which are easier to correct by getting new tag and reapplying only needed features, rather than resolving conflicts and reverting redundant features - so this way of work is not possible. On the other hand I do want to see the change, so that I can either rework it to match new version, or submit upstream at a later time.

解决方案

To what I understand, you may use git rebase -i to achieve your goal. Below is the scenario you want to achieve...

A--B--C(develop)
\
 \D--E--F(feature)

you can combine D-E-F as a single commit named as G the final outcome will be

   A--B--C--G(develop)
    \
     \D--E--F(feature)

G is a single commit that have all the things in D-E-F, and you can easily take it off from the develop branch.


So in order to process this surgery, you can do....

git checkout feature_branch

make a temp branch...

git checkout -b temp

git rebase -i develop_branch

and interactive editor will be prompted out... mark commit D and E as squash, retain the last line(commit) as your last single commit save and quit

then a commit G will rebase on to your developement branch.

   A--B--C(develop)--G(temp)
    \
     \D--E--F(feature)

Reset your development onto commit G and delete temp branch if you want.

git checkout develop_branch
git reset --hard <shaSum of commit G>
git -D temp

That's it!

这篇关于合并git分支而不移动分支指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆