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

最后都变了- 提交于 2019-11-30 14:11:06
jessehouwing

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!