问题
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
回答1:
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
来源:https://stackoverflow.com/questions/29975193/how-to-move-a-tracked-file-to-untracked-using-visual-studio-tools-for-git