简体   繁体   English

将克隆的git仓库添加到我的本地仓库

[英]Adding a cloned git repo to my local repo

I cloned a github repo into my repo (let's say https://github.com/foo/bar.git ) to my local git hepo. 我将github存储库克隆到我的存储库中(例如https://github.com/foo/bar.git )到本地git hepo。 After doing git add -A , I see that git only created my_repo/bar/ directory, but didn't add its content ... when I do a push to my github repo, the bar directory is empty. 在执行git add -A ,我看到git仅创建了my_repo/bar/目录,但没有添加其内容...当我将其推送到github repo时, bar目录为空。 How can I add the content of the bar repo into my repo? 如何将bar库的内容添加到我的存储库中? PS: I'm not trying to steal someone's code, it's because the entire project has to go together and bar is a dependence. PS:我不是要窃取某人的代码,这是因为整个项目必须齐心协力,而bar是一种依赖。

Git won't track files of another repository inside yours. Git不会跟踪您内部的另一个存储库的文件。 There are two solutions: 有两种解决方案:

  • Clone the repository and delete the .git directory of the clone repository. 克隆存储库并删除克隆存储库的.git目录。 The cloned repository will be part of your code, not a local repository anymore. 克隆的存储库将成为您代码的一部分,而不再是本地存储库。 You will not push or pull anything to the other repository. 您不会将任何内容推入或拉入其他存储库。

  • Go with Git submodules . 使用Git 子模块 I think it is a better way: 我认为这是一种更好的方法:

git submodule add https://github.com/foo/bar.git bar_local_dir

Try downloading the source code and copy it to the local git repo . 尝试下载源代码并将其复制到本地git repo中。 Once you have done this , then push the code with your changes to your github repo. 完成此操作后,然后将包含所做更改的代码推送到github存储库中。

This is what i interfere from your description. 这就是我干扰您的描述的原因。

What you can do (but a submodule is probably a better way) is the following: 您可以执行以下操作(但子模块可能是更好的方法):

  • Clean up the recipient, to minimize clashes (ie, rename files out of the way, ...) 清理收件人,以最大程度地减少冲突(即,重命名文件,...)
  • Create a new branch for the repository to be integrated, and fetch it's master into it. 为要集成的存储库创建一个新分支,然后将其母版获取到其中。
  • Merge the new branch into the recipient's master branch 将新分支合并到收件人的主分支中

Better experiment on copies, doing this can screw up things badly... 更好地对副本进行实验,这样做会严重破坏内容...

(I did something similar when I squashed notes for two courses into one set of notes. Took me something like a full day until I was convinced nothing had gone missing. Not recommended for everyday use...) (当我将两门课程的笔记压缩成一组笔记时,我做了类似的事情。花了整整一天的时间,直到我确信没有东西丢失。不建议日常使用...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM