4

I accidentally committed my development.sqlite3 file to Git, and it seems to be slowing down my commits. I know about .gitignore, but does this take the file out of my repository once I've done so? My concern is is with reducing the commit and push times.

Newy
  • 38,977
  • 9
  • 43
  • 59
  • 2
    I believe you're looking for http://stackoverflow.com/questions/1143796/git-remove-a-file-from-the-repository-without-deleting-it-from-the-local-filesys You need to add it to .gitignore, but also remove it from the repository. – bobDevil Apr 08 '10 at 21:45
  • 1
    possible duplicate of http://stackoverflow.com/questions/307828/git-remove-file-accidentally-added-to-the-repository – rjh Apr 08 '10 at 21:50
  • quickfix: backup that file, create new with original name, add backup file to .gitignore and commit, than remove backup file from .gitignore and add there the db file, lastly restore the backup:) – Gabriel Ščerbák Apr 08 '10 at 21:53
  • @rjh: Uh, no. That's a very different question. That was about retroactively changing history. This is about .gitigore (among other things). – T.E.D. Apr 08 '10 at 21:54
  • @bobDevil: This is not quite the same thing, as the commit's already been made, so it's `git rm --cached` and `git commit --amend`, not just `rm --cached`. – Cascabel Apr 08 '10 at 22:02
  • @T.E.D. Uh, no. This is also about changing history - the OP needs to fix the bad commit which has already been made. rjh's duplicate is indeed a duplicate. – Cascabel Apr 08 '10 at 22:03
  • @Euwyn: For the record, though I provided an answer here as well, rjh's duplicate question is indeed a duplicate, and you'll likely find more detail there. Just remember to use `rm --cached` to avoid removing the copy in the work tree. – Cascabel Apr 08 '10 at 22:45

3 Answers3

6

There's no need for fanciness with filter-branch - this is just in one recent commit. If not, simply remove the file (git rm --cached <filename>) and amend your commit (git commit --amend). The --cached option tells git to only remove the copy in the index (the commit staging area), and leave the version in the work tree intact.

If it's farther back in the history, you can use interactive rebase (git rebase -i <commit before the bad one> master), choose to edit the bad commit, and rm/amend as before. Be sure to add it to your gitignore as well, of course.

Note that if you've already pushed this commit, you'll have to use push -f to get the non-fast-forward to push, and if anyone else has pulled it already, they'll be annoyed (see the "recovering from upstream rebase" section in the man page of git-rebase.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
1

Try this:

  git filter-branch --tree-filter ´rm filename´ HEAD
Derick Schoonbee
  • 2,971
  • 1
  • 23
  • 39
  • 1
    `filter-branch` is definitely, definitely overkill. The file in question was only added in one commit and has not been modified since. – Cascabel Apr 08 '10 at 22:08
-1

No. All the .gitignore file does is tell the various Git user interface tools to ignore that file when batch-committing changes. You can still manually put any individual file you want into Git's database, and adding entires there will not remove anything from the Git revision database.

T.E.D.
  • 44,016
  • 10
  • 73
  • 134