我试图在GitHub上添加一个分支到主分支,并将一个文件夹推到该分支上。

分支的文件夹结构看起来像- SocialApp/SourceCode/DevTrunk/SocialApp和所有源代码文件都在最后一个文件夹中。

我正在使用以下Git命令:

git add *
git commit -m with the message
git push

这只是将第一个文件夹“SocialApp”推到GitHub上,而忽略了文件夹内的文件夹SourceCode。我怎么解决这个问题?


当前回答

我遇到了这个问题,花费了我一点时间,然后我想起git不会存储空文件夹。请记住,如果您有一个想要存储的文件夹树,请至少将一个文件放在该树最深的文件夹中,例如一个名为“”的文件。Gitkeep”,只是为了影响git的存储。

其他回答

从top directory调用“git add *”和“git add SocialApp”都应该递归添加所有目录。

可能你在SocialApp/SourceCode/DevTrunk/SocialApp中没有文件,这就是原因。

尝试调用touch SocialApp/SourceCode/DevTrunk/SocialApp/。临时的”(并检查。gitignore),然后再次尝试git add。

如果您想递归地添加一个目录和其中的所有文件,请转到要添加的目录所在的目录。

$ cd directory
$ git add directoryname

导航到文件夹,你有你的文件,如果你是在windows机器上,你将需要启动git bash,从中你将得到一个命令行界面,然后使用这些命令

git init   //this initializes a .git  repository in your working directory

git remote add origin <URL_TO_YOUR_REPO.git> // this points to correct repository where files will be uploaded

git add *   // this adds all the files to the initialialized git repository

如果您在将文件合并到主文件之前对其进行了任何更改,则必须通过执行提交更改

git commit -m "applied some changes to the branch"

在这之后,将分支签出到主分支

我只需要这样做,我发现可以很容易地在子目录中添加文件。你只需要在repo的“top目录”上,然后运行如下命令:

$ git add ./subdir/file_in_subdir.txt

这招对我很管用:

git add . --force