Git add . does add files listed in .gitignore

给你一囗甜甜゛ 提交于 2019-12-11 04:18:54

问题


I want to stop tracking certain files in Git that I've added to the .gitignore file.

I used git rm --cached (and also tried git rm -r --cached .) but after running git add ., a git commit --dry-run tells me the files in my gitignore are "to be committed".

The contents of the .gitignore file are:

/source/backup/*
/site/index.php
/site/userscript.user.js

What's wrong with this gitignore?

Things were working just fine when the only line was source/backup/*. As soon as I added the second line, the source/backup/* files are getting committed as well.


回答1:


Clear out your index.

git reset

Stop tracking files in your backup folder.

git rm --cached source/backup/

Commit this change by itself.

git commit -m "Removing backup folder from git."

Proceed normally. Ignored files should not accidentally slip in at this point provided your ignore file is setup properly. I'd recommend preceding it with a slash (assuming that folder exists in the root of your repository).

#.gitignore
/source/backup/
/site/index.php

Open up YouTube. Master git. http://youtu.be/ZDR433b0HJY



来源:https://stackoverflow.com/questions/15774606/git-add-does-add-files-listed-in-gitignore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!