简体   繁体   English

如何将未版本化的代码合并到Git存储库中?

[英]How to merge unversioned code into Git repository?

So a friend worked on a bunch of code that he never versioned, and is handing it off to me. 因此,一个朋友处理了他从未版本化的一堆代码,并将其交给了我。 He initially gave me version A, even though he had a more recent version B available. 他最初给了我版本A,即使他有更新的版本B。 I put A into a git repository (on say Visual Studio Team Services), and then made some commits, resulting in version C. Now he has put up version B in a git repository (on say Bitbucket). 我将A放入git存储库(例如Visual Studio Team Services)中,然后进行了一些提交,生成了版本C。现在,他将版本B放入了git存储库(例如Bitbucket中)。 How can I compare versions C and B, and merge all diffs between (B,A) and (C,A) to get one final version D which has both his updates and mine? 如何比较版本C和B,并合并(B,A)和(C,A)之间的所有差异,以获得一个既包含更新又包含我的最终版本D? Keep in mind, the repos on Bitbucket and TFS (versions B and C respectively) have no common git commits, although they both come off the same base version A. 请记住,虽然Bitbucket和TFS(分别为B和C版本)上的存储库都没有相同的git commit,但是它们都来自相同的基本版本A。

I can see a couple of ways of doing this, not sure of the cons of each though: 1) Add Bitbucket version B as an upstream to my TFS version C, and fetch upstream/master, then do a git diff. 我可以看到几种方法,尽管不确定每种方法的缺点:1)将Bitbucket版本B作为上游添加到我的TFS版本C中,并获取上游/主版本,然后执行git diff。 2) Copy the files from version B into the directory that holds version C, and then commit them as if I changed the files manually. 2)将文件从版本B复制到保存版本C的目录中,然后像我手动更改文件一样提交它们。 3) Something else entirely, like rebase. 3)完全其他的东西,例如变基。

My understanding of git is very basic so please explain like I'm 5 (well, not really, but you know what I mean). 我对git的理解非常基础,因此请像我5岁时一样进行解释(嗯,不是真的,但您知道我的意思)。

Note: It is ok to have all changes made from A to B in one commit in the final repo history, but would be nice to preserve the individual commits between A and C. 注意:可以在最终回购历史记录中的一次提交中完成从A到B的所有更改,但是最好保留A和C之间的单个提交。

Also, from version A to version B, the friend has not maintained directory structure, he has moved all the contents to a sub-directory of the root. 同样,从版本A到版本B,朋友没有维护目录结构,他已将所有内容移动到根目录的子目录中。 So if version A had file a.txt, version B has file TRUNK/a.txt. 因此,如果版本A具有文件a.txt,版本B具有文件TRUNK / a.txt。

Simply: 只是:

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

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