如何使用 Visual Studio Tools for Git 将跟踪的文件移动到未跟踪状态 [英] How to Move a Tracked File to Untracked using Visual Studio Tools for Git

查看:30
本文介绍了如何使用 Visual Studio Tools for Git 将跟踪的文件移动到未跟踪状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始尝试使用 git.无意中将项目中的所有文件添加到团队资源管理器中的包含的更改"中.我在初始提交中提交了所有内容.其中一个文件是 SQL CE 4.0(基于文件的)数据库.我显然在那里傻傻的.我不想跟踪数据库,也不想最终将数据库恢复到以前的某个点.

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.

我的问题是我不知道如何将 SQL CE 4.0 sdf 文件从包含的更改移动到未跟踪.我对 git 没有经验,迄今为止我所知道的只是 Team Explorer UI 中提供给我的内容.

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.

那么,如何将文件从(已提交和)跟踪到未跟踪?在成功操作结束时,我希望将 sdf 文件放在未跟踪"bin 中,并希望将其从已推送到远程存储库的提交中删除.我只是不知道从哪里开始,该做什么

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

推荐答案

要取消跟踪,只需将其删除并提交,这将从存储库的最新版本中删除数据库.从 Visual Studio UI 中这仍然很容易.如果您需要保留 sdf,请将其复制到临时位置.

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.

要从 git 中删除它(并将其保留在文件系统上),您可以发出 从命令行中删除命令.这无法通过 Visual Studio UI 轻松完成.

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.

警告:这将重写历史记录,导致您的所有提交 ID 发生变化.警告

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

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

该文件将不再被引用,并将在某个时候从存储库中删除.要告诉 git 立即删除文件,您需要然后运行:

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

此强制推送需要 TFS 中的其他权限.默认只有项目管理员拥有此权限.

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

这篇关于如何使用 Visual Studio Tools for Git 将跟踪的文件移动到未跟踪状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆