如何在过滤器分支之后更改分支的初始提交
How to change initial commit of branch after filter-branch
在 master
上 filter-branch
之后(添加签收),我有这个 :
A-B-C-D-E-F (master)
A'-X-Y-Z (branch xxx)
其中 A' 是旧的初始提交。我想 "reconnect" 我的分支 "xxx" 掌握,初始提交 A
有这样的东西:
A-B-C-D-E-F (master)
\
X-Y-Z (branch xxx)
怎么做?
谢谢
包含备份选项的三步解决方案:
# 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
您可以按照步骤操作。
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
在 master
上 filter-branch
之后(添加签收),我有这个 :
A-B-C-D-E-F (master)
A'-X-Y-Z (branch xxx)
其中 A' 是旧的初始提交。我想 "reconnect" 我的分支 "xxx" 掌握,初始提交 A
有这样的东西:
A-B-C-D-E-F (master)
\
X-Y-Z (branch xxx)
怎么做? 谢谢
包含备份选项的三步解决方案:
# 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
您可以按照步骤操作。
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