How do you fix a bad merge, and replay your good commits onto a fixed merge?

后端 未结 12 927
时光取名叫无心
时光取名叫无心 2020-11-21 10:25

I accidentally committed an unwanted file (filename.orig while resolving a merge) to my repository several commits ago, without me noticing it until now. I want

12条回答
  •  花落未央
    2020-11-21 10:28

    If it's the latest commit you want to clean up, I tried with git version 2.14.3 (Apple Git-98):

    touch empty
    git init
    git add empty
    git commit -m init
    
    # 92K   .git
    du -hs .git
    
    dd if=/dev/random of=./random bs=1m count=5
    git add random
    git commit -m mistake
    
    # 5.1M  .git
    du -hs .git
    
    git reset --hard HEAD^
    git reflog expire --expire=now --all
    git gc --prune=now
    
    # 92K   .git
    du -hs .git
    

提交回复
热议问题