简体   繁体   English

Git和克隆

[英]Git and cloning

I have done an app for a client called 'A' (not really). 我已经为一个名为“ A”的客户开发了一个应用程序(不是真的)。

I have found out that it is very cool and that I want to sell it to other clients also. 我发现它非常酷,我也想将其出售给其他客户。 The directory 'A' is a Git repository. 目录“ A”是一个Git存储库。 I think I have a problem with cloning it. 我认为克隆有问题。 As far as I can see I need to make a copy of the dir 'A' and call it 'Generic_A'. 据我所知,我需要复制目录“ A”并将其命名为“ Generic_A”。 Then delete the dir 'A' and do a "git clone Generic_A A" Then I could start changing the 'Generic_A'-repo with a generic design and all client references removed. 然后删除目录“ A”并执行“ git clone Generic_A A”,然后我可以开始更改具有通用设计的“ Generic_A” -repo,并删除所有客户端引用。 But that is kind of the other way around. 但这是另一回事。 I should have started doing the generic design and then cloned the repo to change to the client specific design. 我应该开始进行通用设计,然后克隆存储库以更改为特定于客户的设计。

Can I: 我可以吗:

  1. make a new branch 新建一个分支
  2. do all the changes to make the design generic 进行所有更改以使设计通用
  3. create a patch that reflects the changes between the two 创建一个补丁,以反映两者之间的变化
  4. remove the client specific branch 删除客户端特定的分支
  5. rename the directory to 'Generic_A' 将目录重命名为“ Generic_A”
  6. clone the repo to a new dir 'A' 将存储库克隆到新目录“ A”
  7. apply the patch to get the client specific stuff back 应用补丁以获取客户特定的东西

And if yes - how do I make the patch and apply it? 如果是,我该如何制作补丁并应用它?

Regards, 问候,

Jacob 雅各

Here a possible work-flow : 这是一个可能的工作流程:

  • On A dir : 在目录上:
    • Create a new branch 'generic' from branch 'client-A'. 从分支“ client-A”创建一个新的分支“ generic”。
    • Use 'git rebase -i' on 'Generic' branch to remove all client A stuffs. 在“通用”分支上使用“ git rebase -i”删除所有客户端A的东西。
    • Use 'git rebase client-A generic' to rebase your client-A branch on the generic one. 使用'git rebase client-Ageneric'将您的client-A分支基于通用分支。
  • Rename your A dir to generic dir 将您的A目录重命名为通用目录
  • clone your generic dir to a new client-A dir 将您的通用目录克隆到新的客户端-A目录
  • remove client-A branch from generic dir. 从通用目录中删除client-A分支。

This way, you will keep the history of the client-A branch. 这样,您将保留client-A分支的历史记录。

That could work, although between 6. and 7. I would make a 'client_A' branch before applying your patch. 即使在6到7之间,也可以使用。在应用补丁之前,我将创建一个'client_A'分支。
The drawback is that you lose commit history specifics to client A, since you apply that patch in one big commit. 缺点是您会丢失对客户端A的提交历史记录详细信息,因为您是在一次大提交中应用了该补丁的。

In your case, a patch can be made with git diff , see patching with git diff 在您的情况下,可以使用git diff制作补丁 ,请参见使用git diff进行补丁

git diff --no-prefix > patchfile

then apply the patch: 然后应用补丁:

patch -p0 < patchfile

If you have an existing " git diff " patch file that was created without the "--no-prefix" option, you can apply that patch via: 如果您已经创建了不带“ --no-prefix”选项的现有“ git diff ”补丁文件,则可以通过以下方式应用该补丁:

patch -p1 < patchfile

this will ignore the default a/ b/ source prefixes. 这将忽略默认的a / b /源前缀。

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

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