Git remove duplicate commits

前端 未结 3 701
耶瑟儿~
耶瑟儿~ 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:35

    An the end I decided in favour of cherrypicking.

    0 讨论(0)
  • 2021-01-13 21:45

    With a bit of shell magic, grepping and a lot of confidence, then the answer is probably "yes". But I'd be too leery of completely messing things up to squash over 3000 commits with a single command!

    However, you can do it (moderately) interactively by using interactive rebasing. It's a bit laborious, but you have good control over what's happening and you get good feedback from git.

    0 讨论(0)
  • 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)

    ~

    0 讨论(0)
提交回复
热议问题