【问题标题】:GitHub: Apply master commits to another branchGitHub:将主提交应用到另一个分支
【发布时间】:2014-02-20 04:52:02
【问题描述】:

与此问题相关的存储库位于here

我使用
从 master 分支创建了一个名为 apt-offline-python3-dev 的新分支 GitHub 网页界面。

我想要做的是从提交774-784 接管来自主分支的提交,因此使它们属于apt-offline-python3-dev 分支,而不是属于master 分支。

因为,例如,当您查看 latest 提交时,它清楚地表示 ma​​ster 而不是 apt-offline-python3-dev,这是合乎逻辑的,因为我发送所有这些提交到主分支, 在重构存储库之前。

然后我想将 master 分支重置回其原始状态,这意味着返回提交 9f2f667d13,如 2013 年 6 月 16 日的 this 页面所示。​​

现在,我知道git cherry-pickgit merge,但根本不知道这是否可能。

更新:
+1 为马特的回答引导我朝着正确的方向前进。不幸的是,问题仍然存在。
当我按照 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

现在剩下的问题是:我如何保留提交哈希值还是不可能?

【问题讨论】:

    标签: git github branch git-commit


    【解决方案1】:

    使用 git cherry-pick 将更改从 master 应用到所需的分支:

    git checkout apt-offline-python3-dev
    git cherry-pick <sha1>
    git cherry-pick <sha1>
    ...
    

    然后,在一个单独的步骤中,将更改还原为 master:

    git checkout master
    git revert <sha1>
    git revert <sha1>
    ...
    

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

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 1970-01-01
      • 2016-06-04
      • 2011-05-06
      • 2013-06-08
      • 1970-01-01
      • 2012-12-03
      • 2016-09-15
      • 1970-01-01
      相关资源
      最近更新 更多