Can I squash commits in Mercurial?

后端 未结 8 1717
时光说笑
时光说笑 2020-11-30 20:13

I have a pair of commits that should really be just one. If I was using git, I would use:

git rebase -i 

and then

8条回答
  •  情歌与酒
    2020-11-30 20:53

    Let's assume you want to squash (unite) 2 most recent commits.

    1. Find a revision number

      hg log -G -l 3
      

      possible output:

      @  changeset:   156:a922d923cf6f
      |  branch:      default
      |  tag:         tip
      |  user:        naXa!
      |  date:        Thu Dec 13 15:45:58 2018 +0300
      |  summary:     commit message 3
      |
      o  changeset:   155:5feb73422486
      |  branch:      default
      |  user:        naXa!
      |  date:        Thu Dec 13 15:22:15 2018 +0300
      |  summary:     commit message 2
      |
      o  changeset:   154:2e490482bd75
      |  branch:      default
      ~  user:        naXa!
         date:        Thu Dec 13 03:28:27 2018 +0300
         summary:     commit message 1
      
    2. Soft reset branch

      hg strip --keep -r 155
      
    3. Commit changes again

      hg commit -m "new commit message"
      

    Notes

    strip requires a built-in extension to be enabled. Create/edit ~/.hgrc config file with the following content:

    [extensions]
    strip = 
    

提交回复
热议问题