git 递归地将整个文件夹添加到存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17743549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Recursively add the entire folder to a repository
提问by Ashish Agarwal
I am trying to add a branch to the master branch on GitHub and push a folder onto that branch.
我正在尝试向 GitHub 上的 master 分支添加一个分支,并将一个文件夹推送到该分支上。
The folder structure of the branch looks like - SocialApp/SourceCode/DevTrunk/SocialApp and all the source code files are in the last folder.
分支的文件夹结构看起来像 - SocialApp/SourceCode/DevTrunk/SocialApp 并且所有源代码文件都在最后一个文件夹中。
I am using the following Git commands:
我正在使用以下 Git 命令:
git add *
git commit -m with the message
git push
This is pushing only the first folder "SocialApp" onto GitHub and ignoring the folder SourceCode that is inside the folder. How do I fix this?
这仅将第一个文件夹“SocialApp”推送到 GitHub,并忽略文件夹内的文件夹 SourceCode。我该如何解决?
回答by beyersdorfinger
Check the .gitignore
file, if the subdirectory is ignored.
检查.gitignore
文件,如果子目录被忽略。
Then try again
然后再试一次
git add --all
git commit -am "<commit message>"
git push
回答by Jake Bantug
SETUP - local repository at a local server - client is connected to the local server via LAN
SETUP - 本地服务器上的本地存储库 - 客户端通过 LAN 连接到本地服务器
git add foldername/\*
To make it to the server...
为了让它到服务器......
git commit -m "comments..."
git push remote_server_name master
Mostly, users will assign remote_server_name as origin...
大多数情况下,用户会将 remote_server_name 分配为原点...
git remote add remote_server_name username@git_server_ip:/path/to/git_repo
回答by ykay
This worked for me:
这对我有用:
git add . --force
回答by nopsoft
Both "git add *" and "git add SocialApp" called from top directory should add recursively all directories.
从顶级目录调用的“git add *”和“git add SocialApp”都应该递归地添加所有目录。
Probably you have no files in SocialApp/SourceCode/DevTrunk/SocialApp and this is the reason.
可能你在 SocialApp/SourceCode/DevTrunk/SocialApp 中没有文件,这就是原因。
Try to call "touch SocialApp/SourceCode/DevTrunk/SocialApp/.temporary" (and check .gitignore) and then try git add again.
尝试调用“touch SocialApp/SourceCode/DevTrunk/SocialApp/.temporary”(并检查 .gitignore),然后再次尝试 git add。
回答by disperse
In my case, there was a .git folder in the subdirectory because I had previously initialized a git repo there. When I added the subdirectory it simply added it as a subproject without adding any of the contained files.
就我而言,子目录中有一个 .git 文件夹,因为我之前已经在那里初始化了一个 git repo。当我添加子目录时,它只是将其添加为子项目而不添加任何包含的文件。
I solved the issue by removing the git repository from the subdirectory and then re-adding the folder.
我通过从子目录中删除 git 存储库然后重新添加文件夹解决了这个问题。
回答by Jaime Montoya
I simply used this:
我只是用这个:
git add app/src/release/*
You simply need to specify the folder to add and then use *
to add everything that is inside recursively.
您只需要指定要添加的文件夹,然后使用*
递归添加其中的所有内容。
回答by user7205168
If you want to add a directory and all the files which are located inside it recursively, Go to the directory where the directory you want to add is located.
如果要递归地添加目录及其中的所有文件,请转到要添加的目录所在的目录。
$ cd directory
$ git add directoryname
回答by user2989397
I ran into this problem that cost me a little time, then remembered that git won't store empty folders. Remember that if you have a folder tree you want stored, put a file in at least the deepest folder of that tree, something like a file called ".gitkeep", just to affect storage by git.
我遇到了这个问题,花了我一点时间,然后想起 git 不会存储空文件夹。请记住,如果您有一个要存储的文件夹树,请至少将文件放在该树的最深文件夹中,例如名为“.gitkeep”的文件,只是为了影响 git 的存储。
回答by Suyash Jain
I also had the same issue and I do not have .gitignore file. My problem was solved with the following way. This took all sub-directories and files.
我也有同样的问题,我没有 .gitignore 文件。我的问题是通过以下方式解决的。这需要所有子目录和文件。
git add <directory>/*
回答by Nayyar
Scenario / Solution 1:
Ensure your Folder
/ Sub-folder
is not in the .gitignore
file, by any chance.
场景/解决方案 1:
确保您的Folder
/Sub-folder
不在.gitignore
文件中,无论如何。
Scenario / Solution 2:
By default, git add .
works recursively.
场景/解决方案 2:
默认情况下,git add .
递归工作。
Scenario / Solution 3:git add --all :/
works smoothly, where git add .
doesn't (work).
(@JasonHartley's comment)
场景/解决方案 3:git add --all :/
工作顺利,哪里git add .
没有(工作)。
(@JasonHartley 的评论)
Scenario / Solution 4:
The issue I personally faced was adding Subfolders or Files
, which were common between multiple Folders
.
场景/解决方案 4:
我个人面临的问题是添加Subfolders or Files
,这在多个Folders
.
For example:
Folder/Subfolder-L1/Subfolder-L2/...file12.txt
Folder/Subfolder-L1/Subfolder-L2/Subfolder-L3/...file123.txt
Folder/Subfolder-L1/...file1.txt
例如:
Folder/Subfolder-L1/Subfolder-L2/...file12.txt
Folder/Subfolder-L1/Subfolder-L2/Subfolder-L3/...file123.txt
Folder/Subfolder-L1/...file1.txt
So Git
was recommending me to add git submodule
, which I tried but was a pain.
所以Git
建议我添加git submodule
,我尝试过但很痛苦。
Finally what worked for me was:
1. git add
one file that's at the last end / level of a Folder
.
For example:
git add Folder/Subfolder-L1/Subfolder-L2/Subfolder-L3/...file123.txt
2. git add --all :/
now.
It'll very swiftlyadd all the Folders
, Subfolders
and files
.
最后对我有用的是:
1.git add
一个文件位于Folder
.
例如:
git add Folder/Subfolder-L1/Subfolder-L2/Subfolder-L3/...file123.txt
2.git add --all :/
现在。
它会非常迅速地添加所有Folders
,Subfolders
和files
。