search

Home  >  Q&A  >  body text

How to use rebase to merge several commits in Git

It is said that Git can merge several commits through rebase, and finally leave only the merged one in the history.

Because I submitted several submissions midway when fixing a bug, but in the end I needed to cancel all the intermediate submissions and directly merge the last submission, such as

aaaaaa 修改前小小的重构
bbbbbb 修改拼写错误
cccccc 重算 a 过程
dddddd 重算 b 过程
eeeeee fix #2382

I want to end up with only

in history
abcdef fix #2382,重算了 a、b 过程

What should I do?
I usually use SmartGit, but you can also use the command line to solve it

世界只因有你世界只因有你2821 days ago653

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:24:52

    git rebase -i <eeeee的前一次提交>
    Set the front of unnecessary commits to s, save and exit, and then edit the new log, which is more complicated

    There is another method, but it requires aaaaa to be the latest commit
    git reset --soft <eeeee的前一次提交>然后重新 git commit

    Anyway, these two methods are relatively dangerous operations. It is recommended that novices find a favorite project to try first

    reply
    0
  • Cancelreply