使用git合并两个文件夹 [英] Merging two folders using git

查看:646
本文介绍了使用git合并两个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一些从未使用过git的人一起开展一个项目。不了解git的功能,他们创建了两个版本的项目:开发和生产。这两个版本都出现在当前环境中。



使事情进一步复杂化,除了旧的开发文件夹外,其他用户还创建了这些文件夹。所以项目目录看起来像这样

  / root 
/.git
/ proj(旧的dev文件夹
/ dev_proj(我想合并/ prod的新文件夹)
/ prod_proj(生产代码)

所以我想要做的是将我在 / proj 中完成的工作与在 / dev_proj 中工作。有没有办法用git做到这一点?



我想过创建一个分支,复制所有文件 / proj / dev_proj ,然后将该分支与master进行合并。这会工作吗?



谢谢,如果我可以澄清一些事情让我知道。

我不是一个git专家,但我会建议创建一个新的分支,根源于他在进行更改之前复制其代码的更改。

  git分支devProjTemp< commit-id> 

(别忘了 git checkout devProjTemp 。)然后将所有文件从dev_proj复制到proj,并提交。那么你应该能够从新的分支合并到主,它应该做正确的事情。



如果你想有独立的开发和产品数据,我也会建议为其中之一创建一个分支。具体来说,我将创建一个prod分支,并将prod_proj中的更改复制到该分支。

然后,我会删除master分支和prod分支中的prod_proj和dev_proj。



你的同事不知道分支机构吗?我会在那里做一些教学。一旦你创建了分支,它不应该那么难。


I'm working on a project with some people who have never used git before. Not knowing the capabilities of git, they created two version of the project: development and production. These two versions are both present in the current environment.

To complicate things further, this other user created these folders in addition to the old development folder. So the project directory looks like this

/root
  /.git
  /proj         (old dev folder with my own code in it)
  /dev_proj     (new folder which I would like to merge /prod with)
  /prod_proj       (production code)

So what I'd like to do is merge the work that I've done in /proj with the work in the /dev_proj. Is there a way to do this with git?

I've thought about creating a branch, copying all the files from /proj to /dev_proj and merging that branch with master. Would this work?

Thanks and if I could clarify something let me know.

解决方案

I'm not a git expert, but I would suggest making a new branch, rooted at the change where he copied his code from before making the changes.

git branch devProjTemp <commit-id>

(Don't forget to git checkout devProjTemp.) Then copy all the files from dev_proj to proj, and commit. Then you should be able to merge from the new branch to master and it should do the right thing.

If you want to have separate dev and prod data, I would also suggest creating a branch for one of them. Specifically, I would create a prod branch and copy the changes from prod_proj over to that.

Then, I would delete prod_proj and dev_proj in the master branch and the prod branch.

Does your coworker not know about branches? I would do some teaching there. It shouldn't be so hard once you've created the branches.

这篇关于使用git合并两个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆