Git merge the two commit messages into one message

This question already has an answer here:

  • How can I merge two commits into one? 11 answers

  • 如果你想把两个最后的提交合并成一个给定的名字

    git reset --soft "HEAD^"
    git commit --amend
    

    Since you want to merge the two commits into a new branch as a single commit, you can use this answer.

    Assuming you were in your own topic branch. If you want to merge the last 2 commits into one and look like a hero, branch off the commit just before you made the last two commits.

    git checkout -b temp_branch HEAD^2

    Then squash commit the other branch in this new branch:

    git merge branch_with_two_commits --squash

    That will bring in the changes but not commit them. So just commit them and you're done.

    git commit -m "my message"

    Now you can merge this new topic branch back into your main branch.

    If you just want to merge the two commits into one in your current directory before pushing the code, then use this answer.

    If there are multiple commits, you can use git rebase -i to squash two commits into one.

    If there are only two commits you want to merge, and they are the "most recent two", the following commands can be used to combine the two commits into one:

    git reset --soft "HEAD^"

    git commit --amend

    Safe to say that it is a duplicate but I wanted you to have links to the answer you are looking for.

    链接地址: http://www.djcxy.com/p/23448.html

    上一篇: 在推入Git之前合并多个提交

    下一篇: Git将两个提交消息合并为一条消息