Skip to content

Instantly share code, notes, and snippets.

@chaityacshah
Last active August 18, 2018 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaityacshah/fa5f728677b9d0f44f4883052e89ec66 to your computer and use it in GitHub Desktop.
Save chaityacshah/fa5f728677b9d0f44f4883052e89ec66 to your computer and use it in GitHub Desktop.

How can I remove a commit on GitHub?

git log  
git reset --hard ef2ef39d3c2842dd027b42fd96d7b3bc1db6e59d  
git push --force

2: git push -f origin HEAD^:master
3: git push origin +7f6d03:master

This is a very good option:

git push -f origin HEAD^:master SO link

Keep ignored files out of git status As I found here, .gitignore only works for untracked files. If you added files to repository, you can:

git update-index --assume-unchanged <file>
or remove them from repository by

git rm --cached <file>

then use rm to delete the existing files (or folders) and push.

This article explains that too.
Also, I've had this issue come up as well, it's probably because you added your ignored directory/files to .gitignore after they were marked as "to be tracked" by GIT in an initial commit flow.

So you need to clear the git tracking cache like so:

git rm --cached -r [folder/file name]

A more detailed explanation can be read here

The above command also removed the remnants of the folder/files from your remote GIT origin. So your GIT repos become clean.
SO link

Todo:

  1. add tracked files to gitignore
  2. try out other answers for deleting commits from github

read this later [https://stackoverflow.com/questions/3293531/how-to-permanently-remove-few-commits-from-remote-branch]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment