简单地改变整个git分支的正确方法

问题描述 投票:0回答:1

我试图将整个分支重新绑定到主人身上。 Master通过几次新的提交通过了我的第一个分支提交。目前,我使用git reset HEAD~<X>从整个分支创建1个提交,我取消分支我的分支,然后将其提交到单独的临时分支/存储它,然后在主服务器上重新绑定它。有没有更好的办法?

git atlassian-sourcetree
1个回答
0
投票

您有以下选择。从你的问题,我想你可能想要Merge + squash功能分支成为主选项,因为这将导致master上的新提交,其中包含你在feature分支上所做的所有更改,这似乎是你想要实现的,但是我也解释了其他选项,以防你喜欢另一种方法。

Merge feature branch into master

git checkout master
git merge feature

Merge feature branch into master after incorporating master branch changes into feature branch

git checkout feature
git merge master
# Resolve merge conflicts if needed & git commit
git push
git checkout master
git merge feature
# Conflicts are not possible here, 
# since they would have been already resolved in previous merge
git push

Merge + squash feature branch into master.

这将在master上创建一个新的提交,其中包含您从feature分支合并的所有更改。缺点:feature分支提交似乎不包含在master分支中。

git checkout master
git merge --squash feature
git commit
git push

Rebase entire feature branch on master

缺点:

  1. feature分支的所有提交都在master分支上重写。因此,feature分支的提交将不会出现在master分支中。
  2. 您最终将不得不在不同的提交中多次解决合并冲突。
  3. 你放松了历史,你会看到feature分支的所有提交在一行

因此,请考虑上述选项之一。

git co master
git rebase feature
git push

Squash feature branch and then merge it into master.

缺点:你需要重写你的qazxsw poi分支的远程历史已被推送到远程。这通常是不可取的。有关详细信息,请参阅qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.