【发布时间】:2016-08-15 04:08:40
【问题描述】:
所以我有一个有帮助的代码更改的提交,但在另一个分支上。
我想将另一个分支中的这个提交应用到我当前分支上的工作副本(而不是另一个提交)。
这可能吗?我该怎么做?
我想分享这与我之前的问题有关,但特定于工作副本: git cherry picking one commit to another branch
【问题讨论】:
所以我有一个有帮助的代码更改的提交,但在另一个分支上。
我想将另一个分支中的这个提交应用到我当前分支上的工作副本(而不是另一个提交)。
这可能吗?我该怎么做?
我想分享这与我之前的问题有关,但特定于工作副本: git cherry picking one commit to another branch
【问题讨论】:
git cherry-pick <SHA-1>...<SHA-1> --no-commit应用由主分支尖端的提交引入的更改,并使用此更改创建一个新的提交。
... 的语法是一个提交范围。抓取从开始(排除)到最后一个的所有提交。如果您希望单个提交使用单个 SHA-1
cherry-pick 不提交默认情况下git cherry-pick提交您的更改,因此如果您希望在不提交所有更改的情况下进行挑选,只需添加-n 标志
这将允许您查看更改并在需要时手动提交它们,或者在遇到太多冲突时中止它。
git cherry-pick -n <hash>
cherry-pick 合并提交如果您需要选择合并而不是提交,请使用 -m 标志
#
# In this case, we select the [1] first parent in the commit
# Use git show <hash> to see a list of available parents
#
git cherry-pick -m 1 <hash>
读出完整的git cherry-pick documentation for all the options you can use
【讨论】:
git fetch remote 刷新)
您仍然可以使用git cherry-pick 命令。见git cherry-pick --help:
-n, --no-commit
Usually the command automatically creates a sequence of
commits. This flag applies the changes necessary to
cherry-pick each named commit to your working tree and the
index, without making any commit. In addition, when this
option is used, your index does not have to match the HEAD
commit. The cherry-pick is done against the beginning state
of your index.
所以您可以只使用git cherry-pick -n <commitid>,更改将应用到您的工作目录并暂存在索引中(如git -a),但不会提交。
【讨论】: