From bce632b28a6b2e94fdb54edb9eb319ccfbc2f6b7 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Mon, 5 Apr 2021 11:19:41 +0300 Subject: [PATCH] Add remove file from commit --- snippets/remove-file-from-commit.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 snippets/remove-file-from-commit.md diff --git a/snippets/remove-file-from-commit.md b/snippets/remove-file-from-commit.md new file mode 100644 index 000000000..99d684dee --- /dev/null +++ b/snippets/remove-file-from-commit.md @@ -0,0 +1,20 @@ +--- +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 ` to remove the specified `` from the index. +- Use `git commit —-amend` to update the contents of the last commit, without changing its message. + +```sh +git rm —-cached +git commit —-amend +``` + +```sh +git rm —-cached "30-seconds.txt" +git commit —-amend +# Removes `30-seconds.txt` from the last commit +```