git cherry-pick. 如何把已经提交的commit, 从一个分支放到另一个分支

问题

在本地master提交了一个commit(8d85d4bca680a5dbcc3e5cfb3096d18cd510cc9f),如何提交的test_2分之上?

方法

使用cherry-pick

用法

git cherry-pick <commit_id>

举例

git checkout test_2
git cherry-pick 8d85d4bc

如果顺利,那么已经提交test_2版本。

如果出现冲突,如

$ git status
On branch test_2
Your branch is up-to-date with 'origin/test_2'.
You are currently cherry-picking commit 0e82d79.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   test_1.txt

解决冲突,然后提交

$ git commit -m 'test_1.txt'
[test_2 55e0fba] test_1.txt
 Date: Tue Aug 16 13:41:06 2016 +0800
 1 file changed, 1 insertion(+), 1 deletion(-)

$ git pull
Already up-to-date.

$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 295 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@******/git_test.git
   bba03ee..55e0fba  test_2 -> test_2

 

posted @ 2016-08-16 13:51  jihite  阅读(10967)  评论(0编辑  收藏  举报