What is .gitignore exactly?

前端 未结 5 875
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 01:05

I just created a Github repository and was wondering what the .gitignore file was for. I started by not creating one, but added one due to the fact that most re

5条回答
  •  时光说笑
    2020-11-28 01:34

    When you are doing a commit you do not want accidentally include temporary files or build specific folders. Hence use a .gitignore listing out items you want to ignore from committing.

    Also, importantly git status is one of the most frequently used command where you want git status to list out the files that have been modified.

    You would want your git status list look clean from unwanted files. For instance, I changed a.cpp, b.cpp, c.cpp, d.cpp & e.cpp I want my git status to list the following:

    git status
    a.cpp
    b.cpp
    c.cpp
    d.cpp
    e.cpp
    

    I dont want git status to list out changed files like this with the intermediary object files & files from the build folder

    git status
    a.cpp
    b.cpp
    c.cpp
    d.cpp
    e.cpp
    .DS_Store
    /build/program.o
    /build/program.cmake
    

    Hence, to get myself free from git status to list out these intermediate temporary files & accidentally committing them into the repo, I should create a .gitignore which everyone does. All I need to do list out the files & folders in the .gitignore that I want to exclude from committing.

    Following is my .gitignore to avoid committing unnecessary files

    /*.cmake
    /*.DS_Store
    /.user
    /build
    

提交回复
热议问题