所以我的提交有一个有用的代码更改,但是在另一个分支上。
我想将另一个分支中的提交应用于当前分支上的工作副本(而不是另一个提交)。
这可能吗?我该怎么做?
以为我愿意与他人分享这与我之前的问题有关,但特定于工作副本: git cherry选择一个提交到另一个分支
所以我的提交有一个有用的代码更改,但是在另一个分支上。
我想将另一个分支中的提交应用于当前分支上的工作副本(而不是另一个提交)。
这可能吗?我该怎么做?
以为我愿意与他人分享这与我之前的问题有关,但特定于工作副本: git cherry选择一个提交到另一个分支
Answers:
git cherry-pick <SHA-1>...<SHA-1> --no-commit
在master分支的顶端应用由提交引入的更改,并使用此更改创建一个新的提交。
的语法为...
提交范围。抓取从开始(排除)到最后一个的所有提交。如果您希望一次提交使用单个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
可以使用的所有选项
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
),但不会提交。