Mercurial: how to undo last unpushed commit?

前端 未结 4 1718
有刺的猬
有刺的猬 2020-12-28 12:30

I have accidentally made a commit to my local repository. To be more specific, I committed changes to lots of files all at once, when I meant to commit them one at a time. <

4条回答
  •  抹茶落季
    2020-12-28 13:02

    commenting and elaborating on @crobar's post cause # of characters is not enough.

    when doing a local commit (no push) then run hg strip -r -1 --keep, it deletes your previous commit AND preserves your list of files waiting to be committed. basically this is a full undo.

    if i use hg strip -r -1 without the --keep, it still deletes your previous commit BUT when i try to list the files to be committed it can't find a change so I wouldn't recommend doing this.

    if i do a commit then do a push (to remote) then do hg strip -r -1 --keep, it does exactly what its supposed to do BUT when you do another commit then push, it creates another branch.

    I.E. 
    
    o----o----Branch (local)
          \
           \
            --o----o----o----Branch (with previous push)
    

    my source/reference: testing these scenarios

提交回复
热议问题