From 0e478ad4cc8c0b8498c1a398822958bf91059f8e Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Tue, 5 Dec 2017 02:27:20 +0530 Subject: [PATCH] Show how a newly added file can be removed (#164) This shows how the user can remove a newly added file from the previous commit. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index ca02a0c..d0f8c3d 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,13 @@ $ git add myfile $ git commit --amend --no-edit ``` +In case the file was newly added to the commit and you want to remove it (from Git alone), do: + +```sh +$ git rm --cached myfile +$ git commit --amend --no-edit +``` + This is particularly useful when you have an open patch and you have committed an unnecessary file, and need to force push to update the patch on a remote. The `--no-edit` option is used to keep the existing commit message.