如何在项目的根目录下向现有git项目添加文件夹?

时间:2018-05-14 20:50:43

标签: git commit subdirectory

我在Mac OS X上使用Git。我的项目根目录中有一个文件夹(与“.git”文件夹处于同一级别),我想添加它以便我尝试

localhost:salesproject satishp$ git add -A myfolder1/
warning: CRLF will be replaced by LF in server.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in web/processor.js.
The file will have its original line endings in your working directory.

然而,当我跑

localhost:salesproject satishp$ git commit -m 'Some changes.'
warning: CRLF will be replaced by LF in server.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in web/processor.js.
The file will have its original line endings in your working directory.
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
    modified:   myfolder1 (modified content)

no changes added to commit

尽管此文件夹中有更改。遵循这个建议 - git add -A is not adding all modified files in directories,我尝试了这个

localhost:salesproject satishp$ git submodule foreach --recursive git add -A .
Entering 'myfolder1'
No submodule mapping found in .gitmodules for path 'myfolder1'

但是当我尝试提交时仍然会遇到相同的错误。如何将我的目录添加到我的Git项目?

编辑:以下是我运行“git status”

时会发生什么
localhost:salesproject satishp$ git status myfolder1/
warning: CRLF will be replaced by LF in server.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in web/processor.js.
The file will have its original line endings in your working directory.
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

    modified:   myfolder1 (modified content)

no changes added to commit (use "git add" and/or "git commit -a")

1 个答案:

答案 0 :(得分:0)

您的问题可能实际上是这样的: No submodule mapping found in .gitmodules for path 'myfolder1'

  1. 我发现有些文章指出要更新/初始化git子模块git子模块更新--init(在使用之前请执行RTFM:git-scm.com/docs/git-submodule);
  2. 然后执行git rm --cached myfolder1

  3. 然后你应该可以 git add myfolder1 ; git commit -m "etc"

  4. (只是转录评论中的回复)