How to delete commits from git on Github and Bitbucket

余生长醉 提交于 2019-12-03 08:54:06

问题


I accidentally pushed up files from my .idea directory in my Django project which I had in my .gitignore file. I am trying to completely delete the commit from my bitbucket repository since there is someone else Im working with on the project and he can't pull my changes without affecting his own .idea files. I have seen other SO questions where they say to use git revert, however I remember there was another command where you pushed the last good commit you made, and everything after that was deleted from the master branch. For example

Commit History:

94ca48e

55fab05

3813803

I want to delete 94ca48e, and 55fab05. There was a command I found once where you could make 3813803 the most current commit, and everything in the remote repository after that commit would be deleted, but I can't find it anywhere.


回答1:


Use git reset --hard 3813803. This can not be undone and works locally as well as remote.

For remote push using git push --force origin master

Have a look at the git docu by Atlassian here.

Let me also quote from there:

Whereas reverting is designed to safely undo a public commit, git reset is designed to undo local changes. Because of their distinct goals, the two commands are implemented differently: resetting completely removes a changeset, whereas reverting maintains the original changeset and uses a new commit to apply the undo.

git reset is the one to be used here, though, because you are asking for complete deletion.



来源:https://stackoverflow.com/questions/38402396/how-to-delete-commits-from-git-on-github-and-bitbucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!