简体   繁体   English

如何阻止 git 跟踪文件夹?

[英]How can i stop git from tracking a folder?

i got a short problem with git.我遇到了 git 的一个小问题。 I found out that git is like tracking my C:\Users\name folder, where name is a placeholder.我发现 git 就像跟踪我的 C:\Users\name 文件夹,其中 name 是占位符。 Because when i am at C:\Users\name and say git status it tells me: '''untracked files [...] nothing added to commit but untracked files present (use "git add" to track) ''' How can i say git that it should not track my users folder?因为当我在 C:\Users\name 并说 git 状态时,它告诉我:'''未跟踪的文件 [...] 没有添加到提交但未跟踪的文件存在(使用“git add”跟踪)'''如何我可以说 git 它应该跟踪我的用户文件夹吗? I read something about.gitignore, but i think this is not working, because i dont want to whole folder to be tracked from git.我读了一些关于.gitignore 的内容,但我认为这不起作用,因为我不想从 git 跟踪整个文件夹。

C:\Users\name_here? C:\Users\name_here?

If git is trying to track your user folder it means that the root of the ropository is in location which has your user folder as its subirectory.如果git正在尝试跟踪您的用户文件夹,则意味着存储库的根目录位于以您的用户文件夹为其子目录的位置。 This could be C:\Users or C:\ .这可能是C:\UsersC:\

You need to copy your repository to a dedicated folder eg C:\git\Project1 .您需要将存储库复制到专用文件夹,例如C:\git\Project1 Please be aware that if you are moving files, you need to move the hidden .git folder.请注意,如果您要移动文件,则需要移动隐藏的.git文件夹。 ( .git folder makes a folder a git reposiotry). .git文件夹使文件夹成为 git 存储库)。

If you're confused, it may be easiest to start in a new folder.如果您感到困惑,从新文件夹开始可能是最简单的方法。


To ignore a folder in git忽略git中的文件夹

You can use a .gitignore file.您可以使用.gitignore文件。

The doco

gitignore - Specifies intentionally untracked files to ignore gitignore - 指定有意忽略的未跟踪文件

To ignore a folder use dir_to_ignore/要忽略文件夹,请使用dir_to_ignore/

Please note that .gitignore should be part of the repository.请注意.gitignore应该是存储库的一部分。

  1. Create a text file called .gitignore at the root of the repository在存储库的根目录创建一个名为.gitignore的文本文件
  2. Add folder_to_ignore/ to it (please note the slash at the end.添加folder_to_ignore/到它(请注意最后的斜线。
  3. git add.gitignore
  4. git commit 'Adding.gitignore'

Solved it by deleting the.git Folder.通过删除.git文件夹解决了这个问题。 But the folder was hidden and therefore in havent seem it但是该文件夹被隐藏了,因此似乎没有

In addition to tymtam's answer, I want to add that if the git is already tracking the directory, adding the.gitignor file will not help and you should use the "git rm" command so that the git stops tracking the file or directory.除了 tymtam 的回答,我想补充一点,如果 git 已经在跟踪目录,添加 .gitignor 文件将无济于事,您应该使用“git rm”命令,以便 git 停止跟踪文件或目录。

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

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