如果不小心提交github提交错了,而 --amend 也不能修改提交者的信息,可以通过尝试下面的方式

  1. Checkout

    bash
    1
    
    git checkout --orphan <latest_branch>
  2. Add all the files

    bash
    1
    
    git add -A
  3. Commit the changes

    bash
    1
    
    git commit -am "commit message"
  4. Delete the branch

    bash
    1
    
    git branch -D main
  5. Rename the current branch to main

    bash
    1
    
    git branch -m main
  6. Finally, force update your repository

    bash
    1
    
    git push -f origin main

缺点是:所有该分支的提交记录都将被删除

Reference