2

Following the Github guide on removing sensitive data seems to result in the offending file being completely removed, including from the directory. Is there a way to remove the offending file from only the git repository (as if it had never been committed), but not remove it from the directory? Obviously it should then be added to the .gitignore file.

Note: this is only a hypothetical question; I haven't actually exposed sensitive information.

Edit: I do realize I could simply copy the file out of the directory, then move it back after following the instructions on Github. I'd like to know if there's a "git way" to accomplish what I'm asking.

Travis Northcutt
  • 24,666
  • 9
  • 42
  • 51
  • Make a backup and restore it after the cleanup? Sorry if it sounds stupid or if I didn't understand the question – CharlesB Feb 07 '13 at 14:48
  • Copy the file somewhere, remove it according to GitHub's guidelines and add it locally again while at the same time adding it to .gitignore. – Dominik Sandjaja Feb 07 '13 at 14:51
  • @CharlesB I realize that would be the "simple" solution - I'm just wondering if there's a way to accomplish what I'm asking using git commands. I edited my question to add that information. Thanks! – Travis Northcutt Feb 07 '13 at 14:54
  • @DaDaDom, just as a point of clarification, files must be added to .gitignore *before* you create them. – Chris Sobolewski Feb 07 '13 at 14:57
  • 1
    Why do you want to add complexity to the git command while you could simply do it with batch scripting? – greydet Feb 07 '13 at 14:57
  • 1
    @ChrisSobolewski your statement is not really true. Actually files may be created before, but they must not be staged. – greydet Feb 07 '13 at 14:58
  • http://stackoverflow.com/questions/5563564/remove-files-from-git-repo-completely – ellotheth Feb 07 '13 at 18:19
  • what @greydet said, plus this is so simple it wouldn't even need a script, just do it. – jthill Feb 08 '13 at 03:54

2 Answers2

3

git rm --cached will delete a file from the index without actually removing the file from the working copy, and you can use git filter-branch as per your-link to purge a file from the history of the repository.

nickgrim
  • 5,387
  • 1
  • 22
  • 28
0

Well to remove it from the git repository. You could follow the steps described in the github page you linked in the question. Just copy your file in another directory and move it back after doing the git procedure.

Now that said if your repository is public (like on github), you can't safely assume that your sensitive data was not already fetched by other users.

greydet
  • 5,509
  • 3
  • 31
  • 51