Git remove duplicate commits

前端 未结 3 699
耶瑟儿~
耶瑟儿~ 2021-01-13 21:05

After some playing with remotes I ended up with all my commits being doubled. E.g. instead of

C3107
..
C3
C2
C1

I got

C31         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 21:46

    git rebase -i #commit id where you want to start squashing#

    This will bring up an interactive session. Switch everything but the first commit on the stack to fixup or squash.

    pick 07520cd Caught file exists issue. # this is last commit
    fixup 3b71b9f Added README.            # fixup will squash the commit
    
    # Rebase b041966..3b71b9f onto b041966
    #
    # Commands:
    #  p, pick = use commit
    #  r, reword = use commit, but edit the commit message
    #  e, edit = use commit, but stop for amending
    #  s, squash = use commit, but meld into previous commit
    #  f, fixup = like "squash", but discard this commit's log message
    #  x, exec = run command (the rest of the line) using shell
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out
    

    I have a git koan (koan 8) that walks you through git rebase -i.

    https://github.com/jbremson/git_koans (work in progress)

    ~

提交回复
热议问题