From 1edbba171b383d6f9f29fc736bd8f90a183cdfe4 Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Wed, 23 Sep 2015 11:26:28 -0400 Subject: [PATCH] Added workflow for removing file from commit --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 929cbc3..9fca9e8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ For clarity's sake all examples in this document use a customized bash prompt in - [What did I just do?](#what-did-i-just-do) - [I want to add changes in one file to two different commits](#i-want-to-add-changes-in-one-file-to-two-different-commits) - [I want to remove a file from git but keep the file](#i-want-to-remove-a-file-from-git-but-keep-the-file) + - [I want to remove a file from a commit](#i-want-to-remove-a-file-from-a-commit) - [I want to change a file name's capitalization, without changing the contents of the file.](#i-want-to-change-a-file-names-capitalization-without-changing-the-contents-of-the-file) - [Clone all submodules](#clone-all-submodules) - [Deleting Objects](#deleting-objects) @@ -569,6 +570,19 @@ Let's say that you just blindly committed changes with `git commit -a` and you'r (master)$ git rm --cached log.txt ``` + +## I want to remove a file from a commit + +In order to remove a file from a commit, do the following: + +```sh +$ git checkout HEAD~2 myfile +$ git add -A +$ git commit --amend +``` + +This is particularly useful when you have an open patch and you have commited an unnecessary file, and need to force push to update the patch on a remote. + ## I want to change a file name's capitalization, without changing the contents of the file.