所以我有一个提交,它有一个有用的代码更改,但它在另一个分支上。
我想将另一个分支中的这个提交应用到我当前分支上的工作副本(而不是另一个提交)。
这可能吗?我该怎么做?
我想分享这与我之前的问题有关,但特定于工作副本: git cherry picking one commit to another branch
最佳答案
如何将所需的提交添加到不同的分支。
git cherry-pick <SHA-1>...<SHA-1> --no-commit
Apply the change introduced by the commit(s) at the tip of the master branch and create a new commit(s) with this change.
...
的语法是一个提交范围。抓取从开始(排除)到最后一个的所有提交。如果您希望单个提交使用单个 SHA-1
cherry-pick
无需 promise
默认 git cherry-pick
提交您的更改,因此如果您希望挑选而不提交所有更改,只需添加 -n
旗帜
这将允许您查看更改并在需要时手动提交它们,或者在遇到太多冲突时中止更改。
git cherry-pick -n <hash>
cherry-pick
merge 提交
如果您需要挑选 merge 而不是提交,请使用 -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 - 将另一个分支上的提交应用到工作副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36778375/