2017-03-23 60 views
1

我有我的特性分支的歷史如下的提交:git的櫻桃挑選和重訂失敗

git lolashortcut described here

[email protected]:~/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 

基本上我不小心合併產地/ 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的櫻桃挑選:

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)然後我試圖變基:

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. 
    [email protected]:~/projects/infoodle$ git log 
    commit 3678770d92b2fd00797d2cda2875c090fc701a1e 
    Author: Jochen Daum <[email protected]> 
    Date: Thu Mar 23 10:48:42 2017 +1300 

     progress 

    commit ed2ca95096690c4c419ef491ad65c3c5020120e5 
    Merge: 30ef79c 0743777 
    Author: Jochen Daum <[email protected]> 
    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 

但這些2個提交我特別不想。

我在做什麼錯?

+0

在'櫻桃pick'命令,這真是你寫fec8c04 .0743777還是你拼寫出每個提交單獨?我認爲你必須單獨編寫它們,除非你想要一系列的提交。 –

回答

3

git cherry-pick的問題很簡單:

我要現在開始要提交75a78ce(在底部)和應用[承諾入手,和包括fec8c04,所以我跑]

git cherry-pick fec8c04..0743777 

記號X..Y在GIT中是指「所有提交可達從Y不含所有提交從X可達「。這不包括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方法行不通以及將選擇太多提交到複製到一個線性序列)。

+0

謝謝你,優秀的答案。我編輯了問題重新分支-b vs git checkout -b – jdog