我正在尝试向 GitHub 上的主分支添加一个分支,并将一个文件夹推送到该分支上。
分支的文件夹结构看起来像 - SocialApp/SourceCode/DevTrunk/SocialApp,所有源代码文件都在最后一个文件夹中。
我正在使用以下 Git 命令:
git add *
git commit -m with the message
git push
这仅将第一个文件夹“SocialApp”推送到 GitHub 上,并忽略文件夹内的文件夹 SourceCode。我该如何解决?
检查.gitignore文件,如果子目录被忽略。
然后再试一次
git add --all
git commit -am "<commit message>"
git push
设置
更新(2020 年 9 月):使用foldername/\*而不是foldername/\\*:
git add foldername/\*
让它进入服务器...
git commit -m "comments..."
git push remote_server_name master
大多数情况下,用户会将 remote_server_name 分配为来源...
git remote add remote_server_name username@git_server_ip:/path/to/git_repo
这对我有用:
git add . --force
就我而言,子目录中有一个 .git 文件夹,因为我之前在那里初始化了一个 git repo。当我添加子目录时,它只是将其添加为子项目,而不添加任何包含的文件。
我通过从子目录中删除 git 存储库然后重新添加文件夹解决了这个问题。
从顶层目录调用的“git add *”和“git add SocialApp”都应该递归地添加所有目录。
可能您在 SocialApp/SourceCode/DevTrunk/SocialApp 中没有文件,这就是原因。
尝试调用“touch SocialApp/SourceCode/DevTrunk/SocialApp/.temporary”(并检查 .gitignore),然后再次尝试 git add。
我只是用这个:
git add app/src/release/*
您只需要指定要添加的文件夹,然后使用*递归地添加里面的所有内容。
如果要递归添加目录及其中的所有文件,请转到要添加的目录所在的目录。
$ cd directory
$ git add directoryname
我遇到了这个花了我一点时间的问题,然后记得 git 不会存储空文件夹。请记住,如果您有要存储的文件夹树,请至少在该树的最深文件夹中放置一个文件,例如名为“.gitkeep”的文件,以影响 git 的存储。
如果您在 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"
在此结帐后分支到主分支
我也有同样的问题,我没有 .gitignore 文件。我的问题通过以下方式解决。这占用了所有子目录和文件。
git add <directory>/*
场景/解决方案 1:
确保您的Folder/Sub-folder不在.gitignore文件中,无论如何。
场景/解决方案 2:
默认情况下,git add .递归工作。
场景/解决方案 3:
git add --all :/工作顺利,哪里git add .不(工作)。
(@JasonHartley 的评论)
场景/解决方案 4:
我个人面临的问题是添加Subfolders or Files,这在多个Folders.
例如:
Folder/Subfolder-L1/Subfolder-L2/...file12.txt
Folder/Subfolder-L1/Subfolder-L2/Subfolder-L3/...file123.txt
Folder/Subfolder-L1/...file1.txt
所以Git建议我添加git submodule,我试过但很痛苦。
最后对我有用的是:
1.git add一个位于Folder.
例如:
git add Folder/Subfolder-L1/Subfolder-L2/Subfolder-L3/...file123.txt
2.git add --all :/现在。
它会非常迅速地添加所有Folders,Subfolders和files.
有时我想将我的 Web 服务源代码连同它的客户端项目一起包含在内。它们都有一个单独的 git 存储库。我实际上习惯于使用以下命令添加所有文件:
git add -A
但由于某种原因,它只添加了文件夹。后来我发现服务器文件也有它的.git文件夹,所以命令不起作用。
tl; dr.git :确保您要暂存的文件夹内没有文件夹。
git add --all my/awesome/stuff/为我工作。[1]
我只需要这样做,我发现您可以轻松地在子目录中添加文件。您只需要位于 repo 的“顶级目录”,然后运行类似:
$ git add ./subdir/file_in_subdir.txt
这对我有用
git add -f *