43

I just created a new git repo at / I created a new filetest.txt in the folder test_fold so that the path to the file is test_fold\test.txt. I then run git status. This is the output, it finds the folder but not the file. Why is not showing me that there is a new file in test_fold?

$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        test_fold/

nothing added to commit but untracked files present (use "git add" to track)

The .gitignore file is blank.

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
Vader
  • 6,335
  • 8
  • 31
  • 43
  • 1
    As far as i know, you have to add some placeholders to empty folders, to be synced with git. – Tamás Szabó Jan 29 '15 at 19:10
  • 4
    That's just the way Git displays untracked files when the directory doesn't contain any tracked files. Once you have added at least one file inside the directory, `git status` will show individual files inside the folder. – ChrisGPT was on strike Jan 29 '15 at 19:10
  • @Chris so once I add the directory git will scan the contents of the directory? – Vader Jan 29 '15 at 19:11
  • 1
    @Vader, yes. You can either `git add test_fold/test.txt` to add that specific file, or `git add test_fold` to add all files inside the directory. In this case it amounts to the same thing. Note that Git doesn't track directories at all, so if you try this with an empty folder nothing will get added. – ChrisGPT was on strike Jan 29 '15 at 19:12
  • Is there an actual question? I just see a statement of facts... which look just like they should... – twalberg Jan 29 '15 at 20:51

2 Answers2

81

Git will ignore the content of a folder if the folder doesn't already contain tracked paths. You know by the presence of test_fold/ that there are files in there (Git will never show you an empty directory as being untracked) and you know that those files are not tracked.

Otherwise, unzipping a folder into your repository could potentially introduce huge amounts of output from git status. The default behavior of simply showing the top-level untracked path makes for much saner output.

If you want Git to show you the content of the folder, use

$ git status -uall

This will show you test_fold/test.txt (and any other files) instead of just test_fold/.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • It's not actually in my root folder, the important thing was the relative path. – Vader Jan 29 '15 at 19:15
  • You said this "Otherwise, unzipping a folder into the root of your repository could potentially introduce huge amounts of output from git status" but my repo is not actually in root – Vader Jan 29 '15 at 19:18
  • 1
    @Vader Unzipping a folder *anywhere* in your repository is identical to unziipping it into the root. The point is that there is no reason for Git to show you the contents of a directory, if all those contents are untracked. – user229044 Jan 29 '15 at 19:18
1

GIT will never track empty folder, Add a temporary file, so that git will show on git status

Khn Rzk
  • 1,124
  • 2
  • 15
  • 26