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

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

问题描述

开始尝试使用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没有经验,而且我所知道的所有信息都是团队资源管理器用户界面中提供给我的。

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文件放在未跟踪容器中,并希望将其从已推送至远程回购的提交中删除。我只是不知道从哪里开始以及做什么

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:\temp\tempfolder
  --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

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

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