我有两个分支,电子邮件和分期。分期是最新的一个,我不再需要旧的更改在电子邮件分支,但我不想删除他们。

我只想将所有staging的内容转储到电子邮件中,以便它们都指向同一个提交。这可能吗?


当前回答

我已经看到了几个答案,这是唯一的程序,让我解决没有任何冲突。

如果你想要在branch_old中对branch_new的所有更改,那么:

git checkout branch_new
git merge -s ours branch_old
git checkout branch_old
git merge branch_new

一旦应用了这四个命令,您就可以毫无问题地推送branch_old了

其他回答

我想合并两个分支,以便old_branch中的所有内容都与new_branch中的内容更新

对我来说,这就像一个魔法:

$ git checkout new_branch
$ git merge -m 'merge message' -s ours origin/old_branch
$ git checkout old_branch
$ git merge new_branch
$ git push origin old_branch

我已经看到了几个答案,这是唯一的程序,让我解决没有任何冲突。

如果你想要在branch_old中对branch_new的所有更改,那么:

git checkout branch_new
git merge -s ours branch_old
git checkout branch_old
git merge branch_new

一旦应用了这四个命令,您就可以毫无问题地推送branch_old了

这个分支不会改变原来更新的分支,并让您有机会在最终提交之前进行进一步的修改。

git checkout new -b tmp
git merge -s ours old -m 'irrelevant'
git checkout old
git merge --squash tmp
git branch -D tmp
#do any other stuff you want
git add -A; git commit -m 'foo' #commit (or however you like)

其他答案给了我正确的线索,但它们并没有完全起作用。

以下是对我有效的方法:

$ git checkout email
$ git tag old-email-branch # This is optional
$ git reset --hard staging
$
$ # Using a custom commit message for the merge below
$ git merge -m 'Merge -s our where _ours_ is the branch staging' -s ours origin/email
$ git push origin email

如果没有与我们的战略合并的第四步,推送被认为是非快进更新,将被拒绝(GitHub)。

如何:

git branch -D email
git checkout staging
git checkout -b email
git push origin email --force-with-lease