簡體   English   中英

合並多個提交git

[英]Merge multiple commits git

我的分支中有以下提交

$ git log --pretty=oneline 
    aa2ea957db6bf5f097b0e2f046c4c3f76758c6d9 Merge branch 'CentralCache_Stats' of gi  ==>  When I pull from master it create new commit don't why ?
    4ece4416421334e8be75893ef1416bb8509d2a44 [744] New API for central cache informa  ==>  I make changes and did commit --amend then also it create new commit.
    a49d7ef9f2e0c7adedb8dee96f79ce1d9e2855db Merge branch 'master' of github.com:gsh  ==> When I pull from master it create new commit don't why ?
    b632ef35f7776e365e36b508d8e490b429646317 [744] New API for central cache informa  ==> I make changes and forgot to add commit --amend
    a8c54056cb3012fb8da7221b419857422b168046 [744] New API for central cache informa  ==> I make come change
    64892ae730b704a7f3f23bd8eaeaf206901df201 lower default transfer batch size down ==> This is master change

現在,我想將所有提交合並到一個。

$ git log --oneline --graph --decorate
*   aa2ea95 (HEAD, CentralCache_Stats) Merge branch 'CentralCache_Stats' of githu
|\  
| *   a49d7ef (origin/CentralCache_Stats) Merge branch 'master' of github.com:gsh
| |\  
| | * a8c5405 (origin/master, origin/HEAD, master) [744] New API for central cach
| * | b632ef3 [744] New API for central cache information
| |/  
* | 4ece441 [744] New API for central cache information
|/  
* 64892ae lower default transfer batch size down to 512

Ahhh such a mess

一種解決方案是我通過git reset HEAD ^ n返回並執行--amend,但是問題是我更改了很多代碼,因此解決沖突將成為問題

我試着做

git rebase 
s aa2ea957db6bf5f097b0e2f046c4c3f76758c6d9 Merge branch 'CentralCache_Stats' of gi
p 4ece4416421334e8be75893ef1416bb8509d2a44 [744] New API for central cache informa
p a49d7ef9f2e0c7adedb8dee96f79ce1d9e2855db Merge branch 'master' of github.com:gsh
p b632ef35f7776e365e36b508d8e490b429646317 [744] New API for central cache informa
p a8c54056cb3012fb8da7221b419857422b168046 [744] New API for central cache informa
p 64892ae730b704a7f3f23bd8eaeaf206901df201 lower default transfer batch size down 

我收到錯誤,如果沒有先前的提交就無法壓榨

git log
commit 6bf5f097b0e2f046c4c3f76758c6d9
Merge: 4ece441 a49d7ef
....

commit 4ece4416421334e8be75893ef1416bb8509d2a44
....

commit a49d7ef9f2e0c7adedb8dee96f79ce1d9e2855db
Merge: b632ef3 a8c5405
....

commit b632ef35f7776e365e36b508d8e490b429646317
....

commit a8c54056cb3012fb8da7221b419857422b168046
....

commit 64892ae730b704a7f3f23bd8eaeaf206901df201
....

如何合並或解決這個問題?

您只需要關心主分支中的提交即可。 例如,如果您的歷史記錄看起來像這樣,並且您的HEAD位於I

master   A---B---H-------I
              \         /  
branch1        C---E---G
                \     /
branch2          D---F

然后,你可以做git reset A --mixed其中AHEAD~3在這種情況下。 現在,HEAD在A並且--mixed保留了您的更改,您應該能夠一次全部提交它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM