.gitignore 不忽略目录
我做了什么:
我认为 github gui 中有一些奇怪的配置导致了这个问题,并阻止我从命令行轻松使用 git 甚至 git-bash。
我最终只是卸载了 github 和 git,然后重新安装了 Windows 版 git。我现在所有的东西都可以从命令行运行(除了我从 git-bash 运行的 ssh )。比 github gui 更容易、更可靠。
感谢 mu 无 花时间尝试解决这个问题。我最终没有使用他的答案,但如果我不需要重新安装 git,这就是我需要做的。
我在本地计算机上使用 github gui。我刚刚注意到我即将进行的提交将更新我最近更新的所有节点模块。我将 .gitignore 设置为忽略整个 node_modules/
目录。
我不知道该怎么办。我包含在 .gitignore 中的所有文件类型都被忽略。这只是它似乎忽略的目录。
这是我的 .gitignore 文件:
#################
## Sublime Text
#################
*.sublime-project
*.sublime-workspace
#################
## Images
#################
*.jpg
*.jpeg
*.png
*.gif
*.psd
*.ai
#################
## Windows detritus
#################
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#################
## Directories
#################
dev/
cms/core/config/
node_modules/
What I did:
I think there were some weird configurations from the github gui that caused this issue and prevented me from being able to easily use git from command line or even git-bash.
I ended up just uninstalling github and git then reinstalling just git for windows. I now have everything running off the command line(except ssh which I run from git-bash). Much easier and more reliable that the github gui.
Thanks to mu 無 for taking the time to try to figure this out. I didn't end up using his answer, but if I hadn't needed to do a reinstall of git it would have been what I needed to do.
I am using the github gui on my local machine. I just noticed that a commit I was about to make was going to update all of my recently update node modules. I set up my .gitignore to ignore the entire node_modules/
directory.
I'm not sure what to do about this. All the file types I included in .gitignore were ignored. It's just the directories that it seems to ignore.
Here is my .gitignore file:
#################
## Sublime Text
#################
*.sublime-project
*.sublime-workspace
#################
## Images
#################
*.jpg
*.jpeg
*.png
*.gif
*.psd
*.ai
#################
## Windows detritus
#################
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#################
## Directories
#################
dev/
cms/core/config/
node_modules/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
由于
node_modules
目录已作为存储库的一部分进行跟踪,因此.gitignore
规则将不适用于它。您需要使用 git 取消跟踪目录
。您可以在 git-bash 中运行上述 2 步。
此后,
.gitignore
规则将忽略该目录。请注意,一旦您拉取更改,这将从其他存储库中删除目录
node_modules
。只有您进行提交的原始存储库仍会包含node_modules
文件夹。Since the
node_modules
directory is already tracked as part of the repository, the.gitignore
rule will not apply to it.You need to untrack the directory from git using
You can run the above 2 in
git-bash
.After this, the
.gitignore
rule will ignore the directory away.Note that this will remove the directory
node_modules
from your other repos once you pull the changes in. Only the original repo where you made that commit will still have thenode_modules
folder there.与 Zach 类似,我也使用了
echo "node_modules/" >> .gitignore
。问题是它使用编码
UCS-2 LE BOM
创建了文件。使用 notepad++ 我将编码更改为 UTF-8,瞧 - node_modules 现在被忽略了。Similar to Zach, I also used
echo "node_modules/" >> .gitignore
.The problem was it had created the file with encoding
UCS-2 LE BOM
. Using notepad++ I changed the encoding to UTF-8 and voila - node_modules is now ignored.如果文件已经被跟踪,
.gitignore
文件将不会覆盖它。您将需要使用git rm --cached
请参阅
git rm
的完整详细信息:https://www.kernel.org/pub/software/scm/git/文档/git-rm.html
我自己在早期使用 git 时就遇到过一两次这样的情况,这也不太符合我的预期。
If the files are already tracked the
.gitignore
file will not override this. You will need to usegit rm --cached <files>
See the full details on
git rm
athttps://www.kernel.org/pub/software/scm/git/docs/git-rm.html
I ran into this once or twice myself early on with git and it was not quite what I expected either.
如果您使用节点项目,我喜欢这个
.gitignore
:If you work with node projects, I like this
.gitignore
:我遇到了这个问题。不知何故,当我生成文件(使用 echo "node_modules" > .gitignore)时,它在文件开头插入了一个垃圾字符(我责怪 powershell)。
因此,如果您遇到此问题,请尝试删除 .gitignore 并重新开始。
I had this problem. Somehow when I generated the file (using echo "node_modules" > .gitignore) it had inserted a garbage character at the beginning of the file (I blame powershell).
So, if you run into this problem try deleting your .gitignore and starting over.
上面的解决方案都不适合我,我不知道为什么
最终我所做的是:
touch .gitignore
的 .gitignore 文件,并添加了node_modules
git init< 再次初始化了 git /code>
git remote add origin your_repo
再次添加远程git add .
git commit -m 'addedignore file'
git Push -u origin master
并继续使用这个新目录。
请注意,这对我来说是一个解决方案,因为这是我的第一次提交。
None of the solutions above worked for me and I don't know why
Eventually what I did was:
touch .gitignore
at root and addednode_modules
git init
git remote add origin your_repo
git add .
git commit -m 'added ignore file'
git push -u origin master
And continue working with this new directory.
Please note that it was a solution for me because it was my first commit.
那么对我有用的是将“node_modules”添加到 .gitignore
Well what works for me was add "node_modules" to .gitignore
只需从文件夹中删除初始 git 配置即可
rm -rf .git
。使用创建的 .gitignore 文件并添加所有要添加的文件。然后使用git init
重新初始化文件夹中的 git 配置。这将解决您的问题。
Just remove the initial git configuration from your folder by
rm -rf .git
. Use the created .gitignore file and add all the file you want to add. Then reinitialize the git configuration in your folder withgit init
.This will solve your problem.
尝试这个命令,它将解决您的问题:
try this command, it will resolve your issue:
我还没有在任何地方看到过这篇文章,因为也许它应该是显而易见的,直到我忘记了,但在 gitignore 行末尾添加注释实际上并不是注释!自己评论就行了!
I haven't seen this posted anywhere, as perhaps it should be obvious, until I forgot, but adding a comment to the end of a gitignore line is NOT actually a comment! Comments on their own line!