git cherry-pick和rebase失败了

时间:2017-03-23 04:05:31

标签: git git-rebase git-cherry-pick

我在主题分支的历史记录中有以下提交:

git lola shortcut described here

jochen@autolaptop4:~/projects/infoodle$ git lola
*   0c61616 (refs/stash) WIP on receipt_preview_sprint_to_finish: 3678770 progress
|\  
| * 332dc8a index on receipt_preview_sprint_to_finish: 3678770 progress
|/  
* 3678770 (HEAD -> receipt_preview_sprint_to_finish, origin/receipt_preview, receipt_preview, integration) progress
*   ed2ca95 Merge branch 'receipt_preview' of bitbucket.org:richinnz/infoodle-web into receipt_preview
|\  
| * 0743777 preview stuff
| * 03a2279 be able to ahndle both rebatable and non-rebatable
| * 1ff3d6c better sample number for preview of receipts
| * 0a0f3ed handle missing {tax receipt} replacement
| * 0ce35c9 remove language files, should not be in git
| * 5cc2b61 identify first key of transaction detail correctly to get data out of transaction record
| * def1132 sort out preview spinner
| * 5622f85 typo when pasting code from master
* | 30ef79c (origin/receipt_search, receipt_search) merge transactiontranslator back into receiptconfigurator
* | 367685c progress transferring sql into configurator
* |   84c71b1 Merge remote-tracking branch 'origin/receipt_search' into receipt_search
|\ \  
| * | 149e5f0 Progress on receipt screen search/ sort/ detail
* | | e927458 processing receiptstodo query into receiptList class, process SQL where parts into ReceiptConfigurator
* | | 80c7c06 list loaded from ajax complete
* | | 99b6ed8 only use global.min when not in debug mode
* | | bf15181 rename
* | | 43fd17a re-indent
* | | 57e38a0 re-indent
* | | c4e7588 save work
| |/  
|/|   
* | 867c918 remove confusing commented out stuff
* | fec8c04 text tweak in phpdoc
|/  
* 75a78ce fix mismatch of function parameter typing after merge

基本上我不小心合并了origin / receipt_search,我们对完成此功能分支的计划进行了更改。

我想现在从提交75a78ce(在底部)开始并应用

0743777 preview stuff
03a2279 be able to ahndle both rebatable and non-rebatable
1ff3d6c better sample number for preview of receipts
0a0f3ed handle missing {tax receipt} replacement
0ce35c9 remove language files, should not be in git
5cc2b61 identify first key of transaction detail correctly to get data out of transaction record
def1132 sort out preview spinner
867c918 remove confusing commented out stuff
fec8c04 text tweak in phpdoc

以相反顺序进入新分支。

1)我尝试过git cherry-pick:

git checkout 75a78ce
git checkout -b receipt_preview_sprint_to_finish
git cherry-pick fec8c04..0743777

应用第二次提交时失败:

On branch receipt_preview_sprint_to_finish
You are currently cherry-picking commit 867c918.
  (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:   code/classes/class.receipting.php

我不明白为什么会发生冲突。

2)然后我尝试了rebase:

git branch -f integration 0743777
git rebase --onto receipt_preview_sprint_to_finish fec8c04~1 integration

    First, rewinding head to replay your work on top of it...
    Fast-forwarded integration to receipt_preview_sprint_to_finish.
    jochen@autolaptop4:~/projects/infoodle$ git log
    commit 3678770d92b2fd00797d2cda2875c090fc701a1e
    Author: Jochen Daum <jd@automatem.co.nz>
    Date:   Thu Mar 23 10:48:42 2017 +1300

        progress

    commit ed2ca95096690c4c419ef491ad65c3c5020120e5
    Merge: 30ef79c 0743777
    Author: Jochen Daum <jd@automatem.co.nz>
    Date:   Thu Mar 23 08:26:23 2017 +1300

        Merge branch 'receipt_preview' of bitbucket.org:richinnz/infoodle-web into receipt_preview

        # Conflicts:
        #   code/ajax/accountcode_functions.php
        #   code/ajax/subinclude/person.php
        #   code/styles/ennz/admin_donationreceipts.tpl.php
        #   code/styles/ennz/header.tpl

但是这两个提交我特别不想要。

我做错了什么?

1 个答案:

答案 0 :(得分:3)

git cherry-pick的问题很简单:

  

我想现在开始使用提交75a78ce(在底部)并应用[提交开头,并包括fec8c04,所以我跑了

git cherry-pick fec8c04..0743777

Git中的符号X..Y表示&#34;所有提交都可以从Y到达,不包括所有可以从X&#34;到达的提交。这排除了X本身。它让人联想到数学中的半开区间,其中[3..5]表示3,4和5,但(3,5)表示仅4和5,或[3,5]表示3和4只要。 (这些是以其他方式编写的,例如] 3,5],并且提交并不是真正的线性 - 我们实际上是在进行集合减法,而不是间隔 - 但这里的想法是充当提醒您X..Y 永远不会包含提交X本身。)

因此,您需要的是:

git cherry-pick 75a78ce..0743777

或:

git cherry-pick fec8c04^..0743777

包含提交fec8c04

值得注意的是,这不是很正确:

git checkout 75a78ce
git branch -b receipt_preview_sprint_to_finish

第二个命令应该是git checkout -b,而不是git branch -b。但是git branch -b会给你一个错误,所以我猜你实际上使用了git checkout -b。 : - )

git rebase方法效果不佳,因为它会选择太多的提交来复制成线性序列。)