Skip to content

Instantly share code, notes, and snippets.

@shang-lin
Last active December 19, 2015 18:28
Show Gist options
  • Save shang-lin/5998320 to your computer and use it in GitHub Desktop.
Save shang-lin/5998320 to your computer and use it in GitHub Desktop.
Git Recipes

Git Recipes

Removing a file from the repository

git rm filename

Removing a file from the repository but keeping the copy in the current working directory

git rm --cached filename

Removing the entire history of a file

git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD

(from Stack Overflow)

Deleting the last commit

To delete the last commit:

git reset --hard HEAD~1

To delete a different past commit:

git reset --hard <sha1-commit-id>

See this Stackoverflow thread for more details.

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