7

Started experimenting with git. Inadvertently added all the files in the project to "Included Changes" in Team Explorer. I committed all in an initial commit. One of those files was the SQL CE 4.0 (file-based) database. I clearly goofed there. I do not want to track the database nor do I want to end up restoring the db back to some previous point.

My problem is I have no idea of how to move the SQL CE 4.0 sdf file from included changes to untracked. I am not experienced with git and all I know to date is what is afforded to me in the Team Explorer UI.

So, how do I move a file from (committed and) tracked to untracked? At the end of a successful operation, I would like to have the sdf file in the "untracked" bin and would like to have it removed from commits which have been pushed up to the remote repo. I just do not know exactly where to start and what to do

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
RRRSR
  • 293
  • 1
  • 3
  • 12

1 Answers1

10

To untrack it, simply delete it and commit that, that will remove the DB from the latest version of the repository. That is still easy from the Visual Studio UI. If you need to keep the sdf, then copy it to a temporary location.

To remove it from git (and keep it in place on the file system) you can issue the remove command from the commandline. This cannot easily be done from the Visual Studio UI.

git rm --cached yourfile.sdf

To remove the unwanted file from the repository completely, you'll need to resort to the commandline. This will remove the file from your history.

WARNING: This will rewite history, causing all your commit ids to change. WARNING

git filter-branch --prune-empty -d c:\temp\tempfolder
  --index-filter "git rm --cached -f --ignore-unmatch yourfile.sdf" 
  --tag-name-filter cat -- --all

The file will no longer be referenced and will be removed from the repo at some point. To tell git to remove the file immediately, you need to then run:

git update-ref -d refs/original/refs/heads/master
git reflog expire --expire=now --all 
git gc --prune=now --aggressive

Finally commit these changes to your remote:

git push origin --all --force

This force push requires additional permissions in TFS. By default only Project Administrators have this permission.

For more explanation, read the linked answers on the related questions.

If your remote repo has branches that you do not have locally, you may need to first pull all branches. You can do so using:

git pull --all
Community
  • 1
  • 1
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • tried git rm --cached StyarterSite.sdf. It showed up in Solution Explorer as Excluded (and went to the "Excluded" folder in Team Explorer - I was expecting the "Untracked" folder). When I committed an unrelated change, the sdf file moved out of the excluded folder and showed up in Solution explorer again as checked-in! If I make a change in the db, it shows up in Team Explorer in the "Excluded" folder again. Bottom line: the rm does not "remove it from git". It is still in the repository both on local and remote. Am I missing something hered? – RRRSR Apr 30 '15 at 19:43
  • To remove it permanently from history and the remote you need to perform the other steps as well. You may also need to add the file to your gitignore file. – jessehouwing Apr 30 '15 at 19:59