【问题标题】:Merge multiple commits git合并多个提交git
【发布时间】:2015-11-26 21:00:48
【问题描述】:

我的分支中有以下提交

$ 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
....

如何合并或解决这个问题?

【问题讨论】:

  • 为什么要这样做?真的是那么乱吗? git log --oneline --graph --decorate 说什么?
  • @Makoto 添加了问题。
  • git reset HEAD~2 --mixed 和git commit 怎么样?

标签: git merge git-merge git-rebase


【解决方案1】:

您只需要关心您的主分支中的提交。例如,如果您的历史记录如下所示,您的 HEAD 位于 I

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

然后您可以执行git reset A --mixed,在这种情况下,A 将是HEAD~3。现在,该 HEAD 位于 A 和 --mixed 留下您的更改,您应该能够一次提交所有更改。

【讨论】:

    猜你喜欢
    • 2018-11-05
    • 1970-01-01
    • 2021-10-06
    • 2012-03-02
    • 1970-01-01
    • 2011-06-23
    • 2013-06-20
    • 2018-07-15
    • 1970-01-01
    相关资源
    最近更新 更多