How to Move a Tracked File to Untracked using Visual Studio Tools for Git

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.

  • Use rebase when Sync in Visual Studio 2015
  • Git: How to rollback/undo a change to an image?
  • Is there a simple way to “git describe” a remote repository?
  • How to handle monolithic project in one root in jenkins with gradle?
  • Is that necessary to install Git server if I want to have remote repository access over ssh?
  • GET pull request merge commit sha from pull request number using github api
  • 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

  • Xcode 7 Git Setup Fail: unable to auto-detect email address
  • Remove all information from a .git directory that can be re-downloaded
  • Running ssh-agent through puppet
  • Is it possible to create branches of git subtrees while maintaining parent repo structure?
  • How to make an alias for git subtree push command with repository and refspec
  • A repo-wide rebase of a commit
  • One Solution collect form web for “How to Move a Tracked File to Untracked using Visual Studio Tools for Git”

    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
    
    Git Baby is a git and github fan, let's start git clone.