Git - Creating a .gitignore file

纵饮孤独 提交于 2019-11-27 03:50:37

Placement of .gitignore depends if the files need to be ignored for just one repo or for all your repos. For one repo, place it in the root of your repo.

When you create a .gitignore file in an existing repo, or add files that were already in the repo, you have to make sure to remove the to-be-ignored files from the repo.

If you have a test.dll in the root, you have to do

git rm --cached test.dll

Now if you have a lot of files, like you said you can opt for the following option, remove everything from the cache, add it all back (the files in .gitignore will not be added) and commit everything again.

git rm -r --cached .
git add .
git commit -m "Start using .gitignore"
Fredrik Pihl

You have to add .gitignore to the index before Git sees it. I.e., git add .gitignore.

The projects that I have worked on, I have the .gitignore file in the root directory of the project, where the .git directory would be. Make sure the file is committed.

Note, that if you have already committed the files you are trying to ignore (i.e. Git is tracking them) then they can't be ignored. You would have to untrack them first.

https://help.github.com/articles/ignoring-files

From the link @thescientist has posted:

Git lets you ignore those files by assuming they are unchanged. This is done by running the

git update-index --assume-unchanged path/to/file.txt

command. Once marking a file as such, git will completely ignore any changes on that file; they will not show up when running git status or git diff, nor will they ever be committed.

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