2

while i'm using git to init the root folder which i've created by use hugo newsite hugo-g, i find not all the subfolders in the root folder are been added to the git.

below are the file permission details:

╰─ 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

below are the result after i've done the action: 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

OS:Darwin robot.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64 git-version: version 2.20.0 hugo-version: Hugo Static Site Generator v0.55.6/extended darwin/amd64 BuildDate: unknown go-version: go version go1.12.5 darwin/amd64

I hope all the subfolder in root folder could be added to the git.

xiaojueguan
  • 870
  • 10
  • 19

3 Answers3

4

git init doesn't add any files. It just creates an (initially empty) repository.

If you want to add all files and subdirectories in the directory to the repository, you need to

git add .
git commit

(The latter command will open a text editor so you can type your first commit message.)

melpomene
  • 84,125
  • 8
  • 85
  • 148
  • @albertjone Your edit shows it worked just fine. Your question doesn't mention that some of those subdirectories are empty. – melpomene Jul 21 '19 at 08:25
1

In your root directory you need to do the following 3 steps to add the files to git repository:

    git add *
    git commit -m "added file to the repo"
    git push
sepideha
  • 1,669
  • 1
  • 11
  • 14
  • Any difference between missing directories & ok ones? Are they nested repository? Do they contain .git file by themselves? – sepideha Jul 21 '19 at 00:37
  • Probably the missing directories have files that are filtered in .gitignore file? Try to check .gitignore file. – sepideha Jul 21 '19 at 00:41
1

with the help of my college huafeng, i finally figured out the reason. As a reason, git won't trace the folder with no file in it. And i also find following answers: Does git ignore empty folders? there says, Git is a content tracker. Empty directories are not content.

xiaojueguan
  • 870
  • 10
  • 19