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

后端 未结 12 911
时光取名叫无心
时光取名叫无心 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:34

    If you haven't committed anything since, just git rm the file and git commit --amend.

    If you have

    git filter-branch \
    --index-filter 'git rm --cached --ignore-unmatch path/to/file/filename.orig' merge-point..HEAD
    

    will go through each change from merge-point to HEAD, delete filename.orig and rewrite the change. Using --ignore-unmatch means the command won't fail if for some reason filename.orig is missing from a change. That's the recommended way from the Examples section in the git-filter-branch man page.

    Note for Windows users: The file path must use forward slashes

提交回复
热议问题