如何将另一个远程分支连接到提交树

How to connect another one remote branch to the commit tree

我有一个带有远程分支的提交树。最近我需要将更改从我的 master 分支推送到另一个远程分支 origin_fsa/master

我添加了新的远程 origin_fsa 并从该远程获取了远程分支,现在它与主提交图分开了。像这样(我使用 TortoiseGit):

我想用我的特定提交重写这个新添加的远程上的所有内容(不需要合并,不需要将这些提交保留在 origin_fas/master 远程分支上,也许只是硬变基)。但是我不知道怎么做。

我希望 origin_fsa/master 远程分支(蓝线)在图片上我当前的主控上。

强制将本地 master 分支推送到 origin_fsa 上的 master 分支:

git push -f origin_fsa master:master

通过使用 TortoiseGit:

如您所见,它是:

push local branch "master"
to the remote branch "master"
on remote "origin_fsa"
with force (actually, it's "--force-with-lease" git option)

请注意,如果您不先 merge/rebase,强制推送可能会丢失远程 "origin_fsa" 上的一些提交。

另请参阅已知更改未知更改选项的提示:


(将鼠标移到这些选项上时会显示这些提示)

我建议首先使用已知更改选项。


如果不使用强制选项,您可能会遇到此错误:

git.exe push --progress "origin_fsa" master:master

To XXX/fsa.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'XXX/fsa.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.