本文介绍了什么是GIT中的跟踪文件和未跟踪文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Git的新手。我想知道什么是跟踪未跟踪文件?
我读过Pro Git,但还是不太明白。

有人可以通过提供示例向我解释两者之间的区别吗?

谢谢,
Nayan

解决方案

如果文件受版本控制,则会跟踪文件。

作为一个小例子,C ++项目将具有

  Makefile 
main.cpp
接口.hpp
worker.cpp

作为源文件;你会把这些放在版本控制之下。在构建过程中,

  main.o 
worker.o
myapp

;这些不属于版本控制,所以你不要在它们上使用 git add 。他们仍然未被跟踪,因为git并不关心他们会发生什么。直到你将它们添加到 .gitignore (默认忽略.o文件),git不知道你想添加还是忽略它们,所以它显示它们 git status 命令直到您做出决定。



是否跟踪文件还取决于版本 - - 假设你自动生成 worker.cpp ,并将其从版本控制中的版本中删除。该文件现在未在该版本中进行跟踪。当你回到版本控制的版本时,git会拒绝在结帐时覆盖该文件。


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 me the difference between the two by providing an example?

Thanks,Nayan

解决方案

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.

这篇关于什么是GIT中的跟踪文件和未跟踪文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 16:27