简体   繁体   English

git ignore和untrack之间的区别

[英]difference between git ignore and untrack

What's the difference between ignore a folder and untrack in git? 忽略文件夹和git中的untrack有什么区别? I need to remove some folders from my git repository and I am working in Netbeans with the git plugins and put by mistake the build, dist, and nbproject folders in my repository and now I need to remove those folders. 我需要从我的git存储库中删除一些文件夹,我正在使用git插件在Netbeans中工作,并错误地将build,dist和nbproject文件夹放在我的存储库中,现在我需要删除这些文件夹。

If you create a file in your repository named .gitignore, git will use its rules when looking at files to commit. 如果在名为.gitignore的存储库中创建文件,git将在查看要提交的文件时使用其规则。 git will not ignore a file that was already tracked (ie was in the repo) before a rule was added to this file to ignore it. 在将规则添加到此文件以忽略它之前,git不会忽略已经跟踪的文件(即在repo中)。 File must be un-tracked (removed from the repo) using 必须使用未跟踪文件(从回购中删除)

git rm --cached filename

The command will stop tracking but keep the file there intact. 该命令将停止跟踪,但保持文件完好无损。

By "ignore" I assume you mean .gitignore , which is a special file you can make that git will read to determine a set of files and/or directories to ignore. 通过“忽略”我假设你的意思是.gitignore ,这是一个特殊的文件,你可以让git读取它来确定一组要忽略的文件和/或目录。 You can override this, but generally these files will be hidden from any git operation. 您可以覆盖它,但通常这些文件将在任何git操作中隐藏。

"Untracked" in git just means that you haven't added the file to the repository yet. git “Untracked”只表示您尚未将文件添加到存储库中。

If a file is untracked and excluded by the .gitignore , you won't even see it via git status or any other git command. 如果文件未被跟踪并被.gitignore排除,您甚至不会通过git status或任何其他git命令看到它。

To solve your current problem, where you have already accidentally added files that you do not want to track and want to ignore, first add those folders to your .gitignore and then try this command: 要解决当前问题,您已经意外添加了不想跟踪和想要忽略的文件,请先将这些文件夹添加到.gitignore ,然后尝试以下命令:

git rm -r --cached "path/to/ignored/directories"

This will remove the undesired directories from your repo but will not delete them from your local working copy. 这将从您的仓库中删除不需要的目录,但不会从您的本地工作副本中删除它们。

You will want to use untrack instead of gitignore as gitignore won't affect files that are currently being tracked. 您将需要使用untrack而不是gitignore,因为gitignore不会影响当前正在跟踪的文件。 http://git-scm.com/docs/gitignore http://git-scm.com/docs/gitignore

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM