漏合并代码:git cherry-pick

分支代码合并到主干等待预发了,发现分支代码在合并代码之后仍然有代码提交,此时需要将分支后续提交的代码再次合并到主干。此时用cherry-pick

1)查看当前分支git branch 

ANTM0540804_20190531_XXX

2)查看分支上要再次合并到master的commitId,例如我分支上最近3次的要合并到主干

git log --oneline -3(注意是oneline,我首次输入的是online,看着报错一脸懵逼)

d21c480 test3更改
822009b test2更改
3984686 test1更改

3)本地checkout master的代码

git checkout master

4)保证当前master上,按照时间顺序(距离当前时间由远--近)开始操作

git cherry-pick 3984686

----我首次运行命令报错信息如下----

error: could not apply 3984686... test1更改
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

Warning: Your console font probably doesn't support Unicode. If you experience s
trange characters in the output, consider switching to a TrueType font such as L
ucida Console!

解决办法,运行以下三条命令:
git config  core.quotepath off

git config  --unset i18n.logoutputencoding

git config  --unset i18n.commitencoding

再次运行命令:

git cherry-pick 3984686

[master 25e9a6e]test1更改
 1 file changed, 4 insertions(+), 2 deletions(-)

Warning: Your console font probably doesn't support Unicode. If you experience s
trange characters in the output, consider switching to a TrueType font such as L
ucida Console!

5)本地可以在idea上push下,也可以命令行push下

中途遇到的问题:

有冲突:

$ git cherry-pick 822009b
error: 'cherry-pick' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm ' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: cherry-pick failed

到本机代码查找冲突的文件,删除冲突的代码。此时发现有冲突的文件变成了红色的,这时候哪怕处理完了冲突怎么提交这个文件也提交不上。此时git add下这个文件再commit 和push就能成功了

 

 

你可能感兴趣的:(git)