What are tracked files and untracked files in the context of Git?

前端 未结 5 1946
逝去的感伤
逝去的感伤 2021-02-02 08:14

I\'m new to Git. I wish to know what are tracked and untracked files? I read \"Pro Git\", but still couldn\'t quite understand.

Can someone explain to

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 09:00

    A file is tracked if it is under version control.

    As a small example, a C++ project would have

    Makefile
    main.cpp
    interface.hpp
    worker.cpp
    

    as source files; you'd put these under version control. During build,

    main.o
    worker.o
    myapp
    

    are generated; these do not belong under version control, so you do not use git add on them. They remain untracked, because git does not care what happens to them. Until you add them to .gitignore (the .o files are ignored by default), git does not known whether you want to add or ignore them, so it displays them with the git status command until you make a decision.

    Whether a file is tracked or not also depends on the version -- suppose you autogenerate worker.cpp and remove it from version control at a later version. The file is now untracked in that version. When you go back to a version where the file was still under version control, git will refuse to overwrite that file during checkout.

提交回复
热议问题