Git: Remove committed file after push

后端 未结 5 850
醉酒成梦
醉酒成梦 2020-12-07 08:34

Is there a possibility to revert a committed file in Git? I\'ve pushed a commit to GitHub and then I realized that there\'s a file which I didn\'t want to be pushed (I haven

5条回答
  •  臣服心动
    2020-12-07 08:46

    If you want to remove the file from the remote repo, first remove it from your project with --cache option and then push it:

    git rm --cache /path/to/file
    git commit -am "Remove file"
    git push
    

    (This works even if the file was added to the remote repo some commits ago) Remember to add to .gitignore the file extensions that you don't want to push.

提交回复
热议问题