git/list[1] front-page[2] threads[3] people[4] search[5] about
 

removing files from history but not filesystem

From
SPShantanu Pavgi <pavgi@uab.edu>
Date
Jun 28, 2011, 06:13 UTC
Message-ID
<CFCCFA00-B4BF-4A88-88A5-2F588630F7BB@uab.edu>
Hi,
How do I delete files from commit history, but still keep these files untracked on the filesystem? 
I tried 'git rm --cached' command using 'git filter-branch'; however it deleted file from the filesystem as well. 

{{{ $ git filter-branch --index-filter 'git rm --cached --ignore-unmatch */one.txt' HEAD }}}

I am guessing since file is getting deleted from commit history (where it was created/modified), it won't be present on the filesystem as well. Am I following it correctly? Any further elaboration on this problem will be really helpful. 

Do I need to move concerned files to some other temporary location and rename them back to original filename? I have tried following commands with tree-filter, but it is failing as of now (second mv command needs to know correct filesystem path which was matched for */one.txt): {{{ $ git filter-branch -f --tree-filter \

> 'if [ -f */one.txt ]; then mv */one.txt */one.txt.keep; fi; rm -f */one.txt; if [ -f */one.txt.keep ]; then mv -f */one.txt.keep */one.txt; fi' \
> HEAD
}}}
 
Any help?

-- Thanks, Shantanu.

Next: Christof Krüger
Message 1 of 6 in “removing files from history but not filesystem”
  1. Shantanu PavgiJun 28, 2011
  2. Christof KrügerJun 28, 2011
  3. Shantanu PavgiJun 29, 2011
  4. Christof KrügerJun 29, 2011
  5. Christof KrügerJun 29, 2011
  6. Shantanu PavgiJun 29, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.