Remove file from amended commit

前端 未结 4 1672
北恋
北恋 2021-02-14 01:31

I pushed a commit to a repo where I accidentally added a file. Nobody else has merged from the remote repo so I can rewrite history. But when I remove file(unstage, not remove f

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 01:36

    Here you go:

    git checkout HEAD~ -- path/to/your/file
    git add path/to/your/file
    git commit --amend -C HEAD
    

    git diff -p HEAD~ -- path/to/your/file | git apply -R
    git commit --amend -C HEAD
    

    git reset HEAD~ -- path/to/your/file
    git commit --amend -C HEAD
    

提交回复
热议问题