在filter-branch
上进行master
(以添加签名)之后,我得到了:
A-B-C-D-E-F (master)
A'-X-Y-Z (branch xxx)
其中A'是旧的初始提交。我想将我的分支“ xxx”“重新连接”到主节点,进行初始提交A
以拥有类似这样的东西:
A-B-C-D-E-F (master)
\
X-Y-Z (branch xxx)
该怎么做? 谢谢
答案 0 :(得分:1)
包含备份选项的三步解决方案:
# create a backup for the branch
git checkout -b backup-xxx xxx
# force position of branch xxx at A
git branch -f xxx A
# get the commits you wanted from the backup branch
git checkout xxx
git cherry-pick X Y Z
在操作之前,您将以backup-xxx
进入xxx状态,以防万一您后悔后悔。
备份计划:
# to restore branch xxx in its previous state
git branch -f xxx backup-xxx
答案 1 :(得分:1)
您可以按照以下步骤进行操作。
git checkout master
git checkout <SHA-HASH-OF-A-AFTER-FILTER-BRANCH> #Now your head should be in detached state at commit-hash of A
git checkout -b <NewConnectedBranch> #B is created from A commit
git cherry-pick X..Z #Applying changes from the disconnected branch