简体   繁体   English

将git repo克隆到非空文件夹

[英]clone git repo to a non-empty folder

I have a large C project under git. 我在git下有一个大型C项目。 Someone else has the same C project but he's not using git. 其他人具有相同的C项目,但他没有使用git。

Both of us started from the same baseline, but I simply did a git init / git add . 我们俩都从相同的基线开始,但是我只是做了git init / git add . and started using git. 并开始使用git。

I'd like to merge my git managed changes into the other branch and init git on his project's folder so we're both synced and use git. 我想将我的git管理的更改合并到另一个分支中,并在他项目的文件夹中初始化git,这样我们就可以同步并使用git了。

How would you do this in git? 您将如何在git中做到这一点?

Your friend should $ git init , $ git add . 您的朋友应该$ git init$ git add . and $ git commit -a his code. $ git commit -a他的代码。

Both of you should have the same remote repository : $ git remote add origin <your-repository-url> (with GitHub it looks like https://github.com/username/repository.git ) 你们两个都应该具有相同的远程存储库: $ git remote add origin <your-repository-url> (在GitHub上看起来像https://github.com/username/repository.git

Your friend has to $ git pull origin master (it will merge the remote branch to his local one) 您的朋友必须$ git pull origin master (它将远程分支合并到他的本地分支)

He just has to $ git push -u origin master so you can $ git pull and it should be ok 他只需要$ git push -u origin master这样就可以$ git pull ,应该没问题

First clone your repo into a blank directory. 首先将您的仓库克隆到一个空白目录中。

Then, in the new repo, create and checkout a new branch for you friend's work. 然后,在新仓库中,为您朋友的工作创建并签出新分支。 The branch point should be the last commit where you both had the same source (probably your initial commit). 分支点应该是两个源都相同的最后一次提交(可能是您的初始提交)。

You then copy his sources into the new tree. 然后,将他的源复制到新树中。 Git status/diff should now show the modifications he made. Git status / diff现在应该显示他所做的修改。

Do git commit on that branch, and you should have one repo with both forks of development. 在该分支上执行git commit ,并且您应该在两个开发分支中都有一个仓库。

Do git merge master to merge your work (which is on the "master" branch) into your colleagues new branch. 进行git merge master来将您的工作(在“ master”分支上)合并到同事的新分支中。 Have fun resolving the conflicts, commit, and you're done. 乐于解决冲突,提交并完成。

If you want the changes back in your own repo, then do you can pull or fetch from his repo, using an ssh:// URL, if you have ssh access to the machine, or file:/// if you can see it directly. 如果您想将更改返回到自己的存储库中,那么您可以使用ssh:// URL(如果您具有对计算机的ssh访问权限)从其存储库中pullfetch ,或者如果可以看到它则使用file:///直。

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

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