I read the book Test-Driven Development with Python, the second chapter describes the creation of a git repository. I follow all instructions, but my .gitignore
file .gitignore
not ignore .gitignore
is written in it. What is the problem?
- fourProbably you added files to .gitignore that already got into your repository try git rm --cached, as it says - Darth
- @Darth, please make your comment a response. - aleksandr barakin
- 2And show the contents of the .gitignore file, but rather the suspicion that there db.sqlite3 can be written not on a separate line, but somewhere after another signature. Judging by the screenshot, it does not seem that the files have already entered the repository, since git status marks them as new. - Jenyay
- I will join the guessing @Darth - etki
- Dmitry, how is your repository? It turned out to solve the problem? - Nick Volynkin ♦
3 answers
I suspect that you added files to the index before you started to ignore. That is, until that git add .
which in the screenshot was another such team. To find out exactly, not enough git status
before adding.
If the file has already been added, the change in .gitignore
does not cause removal from the current index (which is logical and safe).
If files are only added but not yet included in the commit
In this particular case, it is. It is enough to remove them from the index. This command returns the index to HEAD, that is, the state of the last commit.
git reset <file-name>
You may notice that Git itself suggests using another command:
git rm --cached <file-name>
In this case, these commands are equivalent. This duplication has resulted from the evolutionary development of the Git functional. This is also reflected in the documentation and Git messages: reset
recommended somewhere, rm --cached
.
If there are already ignored files in the last commit
Such a situation is also possible, just in case, I will describe her as well. reset
does not work here, rm
needed. The argument --cached
causes Git to remove the file from the index, but not touch the workspace. That is, it literally indexes file deletion, although this deletion was not. If you do this with a file that is not ignored, then after the commit it will be in the category of untracked (untracked).
git rm --cached <file-name>
If you need to remove the entire ignored folder, add the -r switch:
git rm -r --cached <path>
This handy command applies rm
to all files specified in .gitignore
:
git rm --cached `git ls-files -i --exclude-from=.gitignore`
The same option for windows powershell :
foreach ($i in iex 'git ls-files -i --exclude-from=.gitignore') { git rm --cached $i }
Now the result of the git rm
command needs to be fixed with a commit.
git commit -m'removed gitignored files'
Team
git rm --cached `git ls-files -i --exclude-from=.gitignore`
has problems with spaces in titles.
The easiest way is to remove ALL files from the cache, and add them again, taking gitignore into account. all about all 2 teams.
git rm -rf --cached . git add .
then commit:
git commit -m "fix gitignore"
git filter-branch --force (чтобы не удалился каталог с жесткого диска) git filter-branch --tree-filter "rm -rf PATH" HEAD
where PATH is the path to the file / folder
https://help.github.com/en/articles/removing-sensitive-data-from-a-repository