git从一个分支复制提交到另一个分支

时间:2014-10-28 20:15:02

标签: git

那是多么复杂: 我想将最后一次提交从“dev”分支复制到“master”分支。

我这样做

git checkout master
git cherry-pick a6b9463bec0a5240f6e945fbf4951c932751f28d

我收到错误:

git cherry-pick a6b9463bec0a5240f6e945fbf4951c932751f28d
error: could not apply a6b9463... releasing v1.00
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

git status给出了

$ git status
# On branch master
# You are currently cherry-picking.
#   (fix conflicts and run "git commit")
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#
#   both modified:      index.html
#   both modified:      js/boardDims.js
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   config.xml.orig
no changes added to commit (use "git add" and/or "git commit -a")

我不明白为什么将comit复制到另一个分支是如此复杂。 你能给我命令把这个提交复制到我的主分支吗?

由于

3 个答案:

答案 0 :(得分:1)

您正在运行正确的命令,并且它告诉您index.htmljs/boardDims.js中的更改存在冲突。使用diff工具解决冲突,在每个工具上运行git add,最后git commit提交合并。

答案 1 :(得分:1)

当你挑选时,你正在复制一个“改变”,而不是文件本身。复制更改时,该过程非常类似于从dev分支创建最后一次提交的补丁并在主分支上应用该补丁。如果修补程序失败了,那么Git会告诉你解决冲突问题。

虽然大部分时间使用樱桃挑选来获取单个提交,it can be used to grab a series of commits

要解决冲突,您可以使用git mergetool

Here's a visual explanation of cherry picking。 (向下滚动到底部的幻灯片放映)

答案 2 :(得分:0)

它只是“复杂”,因为当你提交时,会出现合并冲突。如果来自不同分支的提交更改了公共文件中的同一行,则这是正常行为。

您可以了解有关解决合并冲突的问题here