最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does git ignore directories starting with period? - Stack Overflow

programmeradmin0浏览0评论

I recently moved from Windows to Kubuntu, and while I was using git to create a new project, I stumbled on something weird: git doesn't seem to ignore folders starting with a period by default. If I remember correcty, Windows version of git did that, and I think I read it on SO but I cannot find a source to back up my words.

Here's output of git status. My gitignore file is empty.

...

Untracked files:
  (use "git add <file>..." to include in what will be commited)
        .build/
        .dist/

...

Am I imagining stuff and this is the correct behaviour? Or is this something that's not supposed to happen?

I recently moved from Windows to Kubuntu, and while I was using git to create a new project, I stumbled on something weird: git doesn't seem to ignore folders starting with a period by default. If I remember correcty, Windows version of git did that, and I think I read it on SO but I cannot find a source to back up my words.

Here's output of git status. My gitignore file is empty.

...

Untracked files:
  (use "git add <file>..." to include in what will be commited)
        .build/
        .dist/

...

Am I imagining stuff and this is the correct behaviour? Or is this something that's not supposed to happen?

Share Improve this question edited Feb 1 at 16:16 Ulrich Eckhardt 17.4k5 gold badges31 silver badges58 bronze badges asked Feb 1 at 15:31 postcoital.solitairepostcoital.solitaire 3121 gold badge2 silver badges13 bronze badges 11
  • 1 "Here's a screenshot" followed by a text in the picture should be "Here's an output" followed by a text in a code block. – 3CxEZiVlQ Commented Feb 1 at 15:51
  • 3 I don't think git/windows ignores folders starting with a period by default. Try to put .*/ in .gitignore – Philippe Commented Feb 1 at 16:25
  • 2 "git doesn't seem to ignore folders starting with a period by default." It doesn't. "If I remember correcty, Windows version of git did that" You remember incorrectly, it also doesn't. I just started W11 in QEMU and did a quick experiment: cd C:\TMP, git init, md .test-dir, echo test >.test-dir\test-file, git status — it shows .test-dir as untracked. Perhaps you've tried with empty directories — but Git always ignores empty dirs because it only tracks file content. – phd Commented Feb 1 at 16:28
  • 2 @postcoital.solitaire "I created a … directory… Then I ran git status." This directory is ignored regardless of the leading dot. The directory will be ignored until you create a file in it. Then it will be visible in git status as untracked. Even in Windows. – phd Commented Feb 1 at 16:35
  • 2 @phd Nevermind. I thought git on Windows did that because when I created a virtual environment with python's venv and named it ".v", it was ignored. Turns out, venv creates a gitignore file to ignore the whole venv directory; not because the name started with a period. My previous comment about creating an empty folder is also null and void, because as you said the folder is empty. – postcoital.solitaire Commented Feb 1 at 16:41
 |  Show 6 more comments

1 Answer 1

Reset to default 2

"Am I imagining stuff and this is the correct behaviour?"

Yes, it is, both on Windows and Linux. Thanks to phd's comment I remembered why I thought it should ignore such folders: I created a virtual environment with python -m venv .v and git ignored it, so I thought that it ignored it because the name started with a period. I didn't take into account that venv itself created a gitignore file with a * which ignored the whole directory, hence it wasn't showing on git status. So yes, I am imagining stuff.

UPD: Seems that python -m venv .v sometimes creates a gitignore file. It does on Windows as of now, but not on Kubuntu.

发布评论

评论列表(0)

  1. 暂无评论