简体   繁体   English

如何将我的git项目更改与不受版本控制的代码合并

[英]How to merge my git project changes with code that is not under version control

We have project named: ABC 我们的项目名为:ABC

I have committed all my source code using Git, but there is another person who worked for me on the same project, didn't use git, and now after 2 months we need to merge our code. 我已经使用Git提交了所有源代码,但是还有另一个人在同一项目上为我工作,没有使用git,现在两个月后,我们需要合并代码。 Is there a way we can do that easily; 有没有一种方法可以使我们轻松地做到这一点? is there any tool available for it? 有没有可用的工具?

First of all have that person's code committed to your repo in a different branch. 首先,将该人的代码提交到另一个分支中的您的存储库中。 Then use git merge to merge with your own branch. 然后使用git merge与您自己的分支合并。 If there is any conflict in merging git will inform and ask you to make changes before merge can take place. 如果合并有任何冲突,git会通知您并要求您进行更改,然后再进行合并。

You can refer these answers to get clear idea: 您可以参考以下答案以获得清晰的主意:

Merging two branch 合并两个分支

Fix merge conflicts. 修复合并冲突。

To get the most accurate merge possible with a minimum of conflicts, you need to know the commit at which you made the snapshot that the other developer worked on; 为了尽可能减少冲突,实现最准确的合并,您需要知道其他开发人员制作快照时所使用的提交。 let's call it abc123 . 我们称之为abc123 Create a branch at that point with git checkout -b myBranch abc123 . 使用git checkout -b myBranch abc123创建一个分支。 Then, overwrite your code with his copy, and do: 然后,用他的副本覆盖您的代码,然后执行以下操作:

git commit
git checkout master   #assuming master is the branch you work on
git merge myBranch

You will most likely have some conflicts, but because you branched off from the snapshot point, git will be able to do a lot of automatic merging for you. 您很可能会发生一些冲突,但是由于您是从快照点分支出来的,因此git将能够为您执行很多自动合并。

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

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