GitHub:将主分支的提交应用到另一个分支

3
这个问题相关的存储库位于此处
我使用GitHub Web界面从主分支创建了一个名为apt-offline-python3-dev的新分支。
我想做的是接管从提交774-784的主分支提交,因此使它们属于apt-offline-python3-dev分支,而不是属于master分支。
因为,比如看最新的提交, 显然它清楚地显示主分支而不是apt-offline-python3-dev,这很合理,因为我在重组存储库之前已经将所有这些提交发送到主分支。
然后我想将主分支重置回其原始状态,也就是回到9f2f667d13提交,如2013年6月16日页面所示。
现在,我知道关于git cherry-pick git merge ,但我真的不知道是否可能。

更新:
感谢Matt的回答,让我朝着正确的方向前进了一步。不幸的是,仍然存在一些问题。
以下是按照Matt建议的顺序执行命令时所发生的情况:

git checkout apt-offline-python3-dev
Branch apt-offline-python3-dev set up to track remote branch apt-offline-python3-dev from origin.
Switched to a new branch 'apt-offline-python3-dev'

git cherry-pick 9f2f667d134330c0de8700258ab98cae0ac89438
error: could not apply 9f2f667... half implementation of lock, please verify
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

由于它已经在这里失败了,所以没有必要调用git revert命令。

现在,如果将顺序颠倒并将git revert替换为git reset --hard,它实际上可以工作:

git reset --hard 9f2f667d134330c0de8700258ab98cae0ac89438
HEAD is now at 9f2f667 half implementation of lock, please verify

git cherry-pick ba8662eb8e01cebc969126650baa22776a27430d
[apt-offline-python3-dev 78c9aa5] Another initial test commit
 Author: codingaround <codingaround@outlook.com>
 24 files changed, 1438 insertions(+), 1328 deletions(-)
 create mode 100644 IMPORTANT_README.md
 rewrite apt_offline_core/AptOfflineMagicLib.py (85%)

一个git log显示,哈希值是新的:

git log
commit 78c9aa5b732d559f141c9bf77c801c1644710432
Author: codingaround <codingaround@outlook.com>
Date:   Mon Sep 30 20:11:55 2013 +0200

    Another initial test commit

现在仍然存在的问题是:如何保留提交哈希或者是否有可能做到这一点?
1个回答

2
使用git cherry-pick将更改从主分支应用到所需的分支:
git checkout apt-offline-python3-dev
git cherry-pick <sha1>
git cherry-pick <sha1>
...

然后,在另一个步骤中,将更改还原到主分支:
git checkout master
git revert <sha1>
git revert <sha1>
...

(git revert会添加新的提交以撤消所做的更改)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接