在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)
怎么做 ?谢谢
包含备份选项的3步骤解决方案:
# 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
你将在操作前的xxx状态下使用backup-xxx
,以防万一你后悔后悔。
后备方案 :
# to restore branch xxx in its previous state
git branch -f xxx backup-xxx
您可以按照步骤操作。
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