Oli*_*ams 37 git atlassian-sourcetree
所以我有一个提交有一个有用的代码更改,但在另一个分支上.
我想在另一个分支中将此提交应用于我当前分支上的工作副本(而不是另一个提交).
这可能吗?我该怎么做?
以为我分享这个与我之前的问题有关,但具体到工作副本: git cherry选择一个提交到另一个分支
Cod*_*ard 52
git cherry-pick <SHA-1>...<SHA-1> --no-commit应用主分支顶端的提交引入的更改,并使用此更改创建新的提交.
该语法...是提交范围.从开始(排除)到最后一个提取所有提交.如果您想要单个提交,请使用单个SHA-1
阅读您可以使用的所有选项的完整git cherry-pick文档
lar*_*sks 19
您仍然可以使用该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.
Run Code Online (Sandbox Code Playgroud)
所以您可以git cherry-pick -n <commitid>,并且更改将应用于您的工作目录并在索引中暂存(如git -a),但不会提交.