3

I've looked around the site but I couldn't find an answer that covers mine entirely, so please excuse me in advance if I missed it.

I inherited a VB.NET project that didn't have source control (it started as a pet project of a long-gone dev and nobody ever bothered after that to put it in), and by a friend's suggestion I thought about using Git for source control.

The project is a niche product that is customized and sold according to the customer's specs, so that brings the problem that even if 95% of the code is the same for all the customers, sometimes up to 10% of the code is changed and tailored for each customer, by changing or adding lines to existing functions, sometimes adding whole blocks of code, but there's no commonality in the changes between different customers (a function changed in one might not be changed in another).

To complicate things further, due to maintenance contracts, updates made to the baseline app have to be replicated in the customer's branches should they want them, and sometimes changes we make for a specific customer are good enough that we want to put them in the baseline app and replicate them to the other customers, BUT keeping the customizations for each customer!

So with my little knowledge of Git, I thought it would be like:

          (customer 1)
         C1-----
(main)  /
A------B------D
        \
         \ (customer 2)
         C2-----
        \
         \ (customer 3)      
         C3-----

...but I can't see how it's going to work after that:

  • Can I merge SOME changes from the customer's branches into the main trunk WITHOUT merging others that are only useful for that customer?
  • Can I merge SOME changes from the main trunk into each customer's branches WITHOUT losing the customizations in those branches?
  • Can I "mark" specific lines of code so they are not merged/committed?
  • Three or more devs will be working in this, each in his own machine but pushing changes to the company's repository for synchronization. What are the implications for this process?
  • Right now, every customer has a separate folder and separate project files with all their source code. How would be the import process to put those folders them into Git?
  • All of this must be done with Visual Studio, with Gitextensions and the Git Source provider for VS. Is it supported, or it has to be done with the console?

Thanks and sorry again if it overlaps with another answer.

4

1 回答 1

0

我对 git 比较陌生,通常在我的所有操作中使用 PoshGit,所以虽然我可能无法在所有事情上为您提供帮助,但我希望我能在一些事情上提供帮助:

  • 我可以将客户分支中的一些更改合并到主干中而不合并仅对该客户有用的其他更改吗?
  • 我可以将主干中的一些更改合并到每个客户的分支中,而不会丢失这些分支中的自定义项吗?

据我了解,这两个操作都可以通过使用git cherry pick来实现,它允许您从一个分支中选择一个特定的提交,并将其添加到另一个分支,而无需将分支合并在一起。

例如,假设您要将对 customer1 的存储库所做的更改添加到 customer2:

首先,您从客户 1 获取要插入到客户 2 的提交的哈希 ID

git checkout customer1Branch
git log 

commit 2e8c40025939e8cf41dec70f213da75aa462184b
Author: xxxxxxx
Date: xxxxxx

This made a change that you want...

然后,您复制要樱桃挑选的哈希的前几个字符,更改为客户 2 的分支并将其樱桃挑选到分支中。

git checkout customer2Branch
git cherry-pick 2e8c40025939e8c

现在,如果您执行 a git log,您将在顶部看到您的樱桃采摘。可以在此处找到类似的教程(http://nathanhoad.net/how-to-cherry-pick-changes-with-git

  • 我可以“标记”特定的代码行以便它们不被合并/提交吗?

您可能会从此处询问和回答的类似问题中找到帮助:

在 Git 中只提交文件的一部分

  • 三个或更多开发人员将在此工作,每个人都在自己的机器上,但会将更改推送到公司的存储库以进行同步。对这个过程有什么影响?

由于 GIT 是一个完全分布式的 VCS,因此您团队中的每个开发人员都将有效地在他自己的机器上拥有中央存储库的完整克隆(包含该存储库的完整历史记录。)这意味着记录历史查询和其他请求(例如查找谁做了什么)不需要通过您的中央服务器,但可以由每个开发人员私下和离线完成。

同样,每个开发人员所做的更改都将可供所有人使用(例如,所有新分支都将可用),但如果您不太习惯 git,有时可能会感到沮丧。

与往常一样,尽早并经常提交是一个好主意,这将减少您在更改发生冲突时可能面临的紧张局势。您还应该在推送完成时设置一些结构,特别是如果您依赖彼此的工作来继续。

您可能想尝试的另一个想法是让一个人负责回购并让他合并更改和补丁以帮助协调您的工作。

  • 现在,每个客户都有一个单独的文件夹和带有所有源代码的单独项目文件。将这些文件夹放入 Git 的导入过程将如何?

编辑

感谢您澄清这个问题的意思。您可以扩展根据此处给出的答案改编的类似方法:您如何创建远程 Git 分支?

为您的 BASE 项目创建一个新的主线分支并将其推送到您的远程存储库。

cd baseProjectDirectory # navigate to your main project directory
git init # git initialize the dir
git add . # recursively add all files in directory to git repo
git remote add <remote-branch-name> <remote-url> # Add the url to your remote directory to your git repo
git commit -m "Initial commit of base project"
git push <remote-branch-name> <local-branch-name>

这将在remote-branch-name名为local-branch-name.

然后,您可以导航到您的其他项目并重复这些步骤,通过使用新的本地分支名称,将您的存储库放在同一个远程的不同分支下,即local-branch-name在创建分支时不要使用,只需使用新的分支名称,例如git checkout -b new-local-branch-name

因此,例如,如果您的基础项目推送(最后一行代码)是:

git push clientproject base

其中“clientproject”是您的远程名称,“base”是您本地分支的名称,您只需将行更改为:

git checkout -b client1 # Creates new branch named client1
git branch -d base # Deletes base branch
git push clientproject client1

请注意,虽然在继续之前删除“base”分支并不是绝对必要的,但它确实使您的存储库更清洁,因此被认为是一种好的做法。不过不要担心丢失任何东西,您从 base 的整个 git 历史记录将在结帐时复制到 client1。

另请注意:由于您的情况需要您从不同的目录执行此操作,因此您可能会删除一个名为“master”而不是“base”的分支。

像这样推送将使 client1 保持在“clientproject”远程,但会将项目放在一个名为 client1 的新分支上,并带有自己的历史记录。

相同的步骤可用于其余项目。如果我一路走失了你,我建议阅读上面的链接(它比我简洁得多)。

  • 所有这些都必须使用 Visual Studio、Gitextensions 和 VS 的 Git 源提供程序来完成。是否支持,还是必须通过控制台完成?

我还没有将 VS 与 Git 一起使用,但我认为大多数(如果不是全部)这些操作都会受到支持,因为它们是本机 git 命令。

希望这可以帮助。

于 2013-02-02T09:28:15.487 回答