Files
30-seconds-of-code/snippets/remove-file-from-commit.md
Isabelle Viktoria Maciohsek bce632b28a Add remove file from commit
2021-04-05 11:19:41 +03:00

21 lines
500 B
Markdown

---
title: Remove a file from the last commit
tags: commit,intermediate
---
Removes a file from the last commit without changing its message.
- Use `git rm —-cached <file>` to remove the specified `<file>` from the index.
- Use `git commit —-amend` to update the contents of the last commit, without changing its message.
```sh
git rm —-cached <file>
git commit —-amend
```
```sh
git rm —-cached "30-seconds.txt"
git commit —-amend
# Removes `30-seconds.txt` from the last commit
```