GIT 不跟踪文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14340001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GIT not tracking files
提问by david.colais
I have setup GIT on AIX 6.1 and am facing problems.
我已经在 AIX 6.1 上设置了 GIT,但遇到了问题。
The sequence of steps I followed are as shown:
我遵循的步骤顺序如下所示:
- I create a folder.
- Go into the folder and initialise the non-bare repository
- Initialise the username and user email
- Create a file named index.html with some data in the file.
- Create a subfolder named newfolder
- Go into the newly created folder.
- Create a new file named index-2.html with some data in it.
- 我创建一个文件夹。
- 进入文件夹并初始化非裸存储库
- 初始化用户名和用户邮箱
- 创建一个名为 index.html 的文件,其中包含一些数据。
- 创建一个名为 newfolder 的子文件夹
- 进入新创建的文件夹。
- 创建一个名为 index-2.html 的新文件,其中包含一些数据。
After performing all the steps above and give the git status
command I'm getting the foll result:
执行上述所有步骤并发出git status
命令后,我得到以下结果:
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ../index.html
# ./
I understand that index.html in the above directory is getting displayed but why doesent index-2.html not getting displayed which is in the current directory.
我知道上面目录中的 index.html 正在显示,但为什么没有显示当前目录中的 index-2.html 。
The file index-2.html should also get tracked right.
文件 index-2.html 也应该被正确跟踪。
回答by poke
The output shows two things that are currently untracked:
输出显示了当前未跟踪的两件事:
../index.html
– theindex.html
file in the parent folder./
– the current folder, including all its contents
../index.html
–index.html
父文件夹中的文件./
– 当前文件夹,包括其所有内容
So it does detect that you have an untracked file, but because it does know nothing about its folder as well, it just shows the folder to accumulate all its content.
所以它确实检测到您有一个未跟踪的文件,但因为它也不知道它的文件夹,它只显示文件夹以累积其所有内容。
If you add your files and make Git track them, they will show up correctly:
如果您添加文件并使 Git 跟踪它们,它们将正确显示:
git add index-2.html
git add ../index.html
回答by martiert
It is tracking the folder ./ which means the current folder. git doesn't (correct me if I'm wrong), care about subfolders at all. Meaning if you have a repository with the folder foo, which is already in the repository. You add a subfolder bar in foo, and create a file foobar.txt in foo/bar. Then you will only get:
它正在跟踪文件夹 ./ 这意味着当前文件夹。git 不(如果我错了请纠正我),根本不关心子文件夹。这意味着如果您有一个文件夹 foo 的存储库,该文件夹已经在存储库中。您在 foo 中添加一个子文件夹 bar,并在 foo/bar 中创建一个文件 foobar.txt。那么你只会得到:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ./bar
Which means that if you had done cd .. before your git status command, you would get:
这意味着如果您在 git status 命令之前执行了 cd .. ,您将获得:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# index.html
# newfolder
even though you have a file inside.
即使你里面有一个文件。
The reason for this is that git tracks content, not files. Since index2.html actually is a content of the folder newfolder, and you are not tracking newfolder, git doesn't know that index2.html exists.
这样做的原因是 git 跟踪内容,而不是文件。由于 index2.html 实际上是文件夹 newfolder 的内容,并且您没有跟踪 newfolder,因此 git 不知道 index2.html 存在。