【问题标题】:do git init in a folder but git failed to add some subfolders在文件夹中执行 git init 但 git 未能添加一些子文件夹
【发布时间】:2019-07-20 15:04:30
【问题描述】:

当我使用 git 来初始化我通过使用 hugo newsite hugo-g 创建的根文件夹时,我发现并不是根文件夹中的所有子文件夹都已添加到 git。

以下是文件权限详情:

╰─ ll -al
total 16
drwxr-xr-x  12 robot  staff   384B Jul 20 22:50 .
drwxr-xr-x  51 robot  staff   1.6K Jul 18 16:22 ..
drwxr-xr-x   9 robot  staff   288B Jul 20 22:50 .git
drwxr-xr-x   3 robot  staff    96B Jul 10 17:56 archetypes
-rw-r--r--   1 robot  staff   7.8K Jul 20 20:23 config.toml
drwxr-xr-x   4 robot  staff   128B Jul 20 21:11 content
drwxr-xr-x   2 robot  staff    64B Jul 10 17:56 data
drwxr-xr-x   2 robot  staff    64B Jul 10 17:56 layouts
drwxr-xr-x  13 robot  staff   416B Jul 20 22:01 public
drwxr-xr-x   3 robot  staff    96B Jul 19 11:13 resources
drwxr-xr-x   2 robot  staff    64B Jul 10 17:56 static
drwxr-xr-x   7 robot  staff   224B Jul 20 22:33 themes

下面是我完成操作后的结果:git init

╰─ git init
Initialized empty Git repository in /Users/robot/code/interests/hugo-g/.git/
╰─ ls
archetypes  config.toml content     data        layouts     public      resources   static      themes
╰─ git status
On branch master

No commits yet

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

    archetypes/
    config.toml
    public/
    themes/

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


#I tried with commands provided by @Sepideha and @melpomene, but it still not works, and the result is like this.

git add .
git status
    new file:   archetypes/default.md
    new file:   config.toml
    new file:   public/404.html
    new file:   public/archives/index.html
    new file:   public/archives/index.xml
    new file:   public/categories/index.html
    new file:   public/categories/index.xml
    new file:   public/css/style-twzjdbqhmnnacqs0pwwdzcdbt8yhv8giawvjqjmyfoqnvazl0dalmnhdkvp7.min.css
    new file:   public/images/cover-v1.2.0.jpg
    new file:   public/images/cover.jpg
    new file:   public/index.html
    new file:   public/index.xml
    new file:   public/js/script-pcw6v3xilnxydl1vddzazdverrnn9ctynvnxgwho987mfyqkuylcb1nlt.min.js
    new file:   public/page/1/index.html
    new file:   public/sitemap.xml
    new file:   public/tags/index.html
    new file:   public/tags/index.xml
    new file:   themes


git add * 
git status

    new file:   archetypes/default.md
    new file:   config.toml
    new file:   public/404.html
    new file:   public/archives/index.html
    new file:   public/archives/index.xml
    new file:   public/categories/index.html
    new file:   public/categories/index.xml
    new file:   public/css/style-twzjdbqhmnnacqs0pwwdzcdbt8yhv8giawvjqjmyfoqnvazl0dalmnhdkvp7.min.css
    new file:   public/images/cover-v1.2.0.jpg
    new file:   public/images/cover.jpg
    new file:   public/index.html
    new file:   public/index.xml
    new file:   public/js/script-pcw6v3xilnxydl1vddzazdverrnn9ctynvnxgwho987mfyqkuylcb1nlt.min.js
    new file:   public/page/1/index.html
    new file:   public/sitemap.xml
    new file:   public/tags/index.html
    new file:   public/tags/index.xml
    new file:   themes

the subfolder like data, content,layouts, resources... still miss.


tree -L 2
╰─ tree -L 2
.
├── archetypes
│   └── default.md
├── config.toml
├── content
│   ├── page
│   └── post
├── data
├── layouts
├── public
│   ├── 404.html
│   ├── archives
│   ├── categories
│   ├── css
│   ├── images
│   ├── index.html
│   ├── index.xml
│   ├── js
│   ├── page
│   ├── sitemap.xml
│   └── tags
├── resources
│   └── _gen
├── static
└── themes
    ├── AllinOne
    ├── BeyondNothing
    ├── Binario

操作系统:Darwin robot.local 18.6.0 Darwin Kernel Version 18.6.0:Thu Apr 25 23:16:27 PDT 2019;根:xnu-4903.261.4~2/RELEASE_X86_64 x86_64 git-version:版本 2.20.0 hugo-version: Hugo 静态站点生成器 v0.55.6/extended darwin/amd64 BuildDate: 未知 go-version: 去版本 go1.12.5 darwin/amd64

希望根目录下的所有子目录都可以添加到git中。

【问题讨论】:

    标签: git


    【解决方案1】:

    git init 不添加任何文件。它只是创建一个(最初是空的)存储库。

    如果要将目录中的所有文件和子目录添加到存储库中,则需要

    git add .
    git commit
    

    (后一个命令将打开一个文本编辑器,以便您输入您的第一条提交消息。)

    【讨论】:

    • @albertjone 您的编辑表明它工作得很好。您的问题没有提到其中一些子目录是空的。
    【解决方案2】:

    在您的根目录中,您需要执行以下 3 个步骤将文件添加到 git 存储库:

        git add *
        git commit -m "added file to the repo"
        git push
    

    【讨论】:

    • 缺少目录和正常目录有什么区别吗?它们是嵌套存储库吗?它们本身是否包含 .git 文件?
    • 可能丢失的目录有在 .gitignore 文件中过滤的文件?尝试检查 .gitignore 文件。
    【解决方案3】:

    在我大学华峰的帮助下,我终于找到了原因。作为一个原因,git 不会跟踪其中没有文件的文件夹。 我还找到了以下答案: Does git ignore empty folders? 那里说,Git 是一个内容跟踪器。空目录不是内容。

    【讨论】:

      猜你喜欢
      • 2018-08-15
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 2014-05-06
      • 1970-01-01
      • 2022-06-20
      • 2012-06-09
      • 1970-01-01
      相关资源
      最近更新 更多