合并同一分支中的文件夹,类似于TFVC中的操作。

huangapple go评论58阅读模式
英文:

Merging folders in the same branch in GIT like TFVC

问题

I've been using TFVC on Azure DevOps for a long time and recently was looking at migrating to Git to take advantage of the easy way branches are created and being able to switch between them easily (as opposed to TFVS where you have to check out the whole branch).

我已经长时间使用Azure DevOps上的TFVC,最近考虑迁移到Git,以利用分支的轻松创建以及能够轻松在它们之间切换的优势(与TFVS不同,你必须检出整个分支)。

TFVS has served me very well and I've got everything setup as I need but I'm finding it difficult in figuring out how this translates to a Git setup.

TFVS一直很好地为我服务,并且我已经设置好了一切,但我发现很难弄清楚如何将其转化为Git设置。

I currently have a situation where I need to merge the changes in one folder to another folder on the same branch.

我目前有这样一种情况,我需要将一个文件夹中的更改合并到同一分支上的另一个文件夹中。

This is so Project "A" can have the "Main" features, while Project "B" can have everything "A" has, along with extra features that shouldn't be in "A".

这样项目“A”可以拥有“主要”功能,而项目“B”可以拥有项目“A”拥有的一切,以及不应该在“A”中的额外功能。

On TFVC, this is as simple as going to Source Control Explorer, right clicking on Project "A" and going to "Branching and Merging", then clicking on "Merge".

在TFVC中,这就像进入“源代码控制资源管理器”,右键单击项目“A”,然后进入“分支和合并”,然后单击“合并”一样简单。

A new window pops up, I select Project "B" and click complete.

一个新窗口弹出,我选择项目“B”并点击完成。

This merges project "A" with "B" so "B" now has everything "A" has including items specific to "B".

这将项目“A”与“B”合并,所以“B”现在拥有项目“A”的一切,包括与“B”相关的项目。

If there's any conflicts, I'll see on VS and can select which values I want to pick easily.

如果有冲突,我会在VS上看到,并可以轻松选择要选择的值。

TFVS works well because I have a Shared Project "Z" which is used across Projects "A" and "B" which does NOT need to be replicated.

TFVS效果很好,因为我有一个共享项目“Z”,该项目跨越项目“A”和“B”使用,不需要复制。

I'm wanting to get something of a similar setup to this after migrating to GIT, but am unable to figure out how I can achieve this through branching on Git.

我希望在迁移到GIT后能够获得类似的设置,但是无法弄清楚如何通过Git上的分支实现这一点。

I thought the best and cleanest way would be to create a new Repo within the Azure DevOps project. However, I'm unable to select a branch from one repo to another when merging (can only merge within the same repo).

我认为最好和最干净的方法是在Azure DevOps项目中创建一个新的存储库。但是,在合并时无法选择从一个存储库合并到另一个存储库的分支(只能在同一个存储库中合并)。

If what I am wanting on Git is not possible - what are the best ways to be able to get this kind of setup?

如果在Git上无法实现我想要的功能,那么能够获得这种设置的最佳方法是什么?

英文:

I've been using TFVC on Azure DevOps for a long time and recently was looking at migrating to Git to take advantage of the easy way branches are created and being able to switch between them easily (as opposed to TFVS where you have to check out the whole branch).

TFVS has served me very well and I've got everything setup as I need but I'm finding it difficult in figuring out how this translates to a Git setup.

I currently have a situation where I need to merge the changes in one folder to another folder on the same branch.

合并同一分支中的文件夹,类似于TFVC中的操作。

This is so Project "A" can have the "Main" features, while Project "B" can have everything "A" has, along with extra features that shouldn't be in "A".

On TFVC, this is as simple as going to Source Control Explorer, right clicking on Project "A" and going to "Branching and Merging", then clicking on "Merge".

A new window pops up, I select Project "B" and click complete.

This merges project "A" with "B" so "B" now has everything "A" has including items specific to "B".

If there's any conflicts, I'll see on VS and can select which values I want to pick easily.

TFVS works well because I have a Shared Project "Z" which is used across Projects "A" and "B" which does NOT need to be replicated.

I'm wanting to get something of a similar setup to this after migrating to GIT, but am unable to figure out how I can achieve this through branching on Git.

I thought the best and cleanest way would be to create a new Repo within the Azure DevOps project. However, I'm unable to select a branch from one repo to another when merging (can only merge within the same repo).

If what I am wanting on Git is not possible - what are the best ways to be able to get this kind of setup?

答案1

得分: 1

A plain git repo can't do this really... But you can accomplish similar scenarios in git, but it's not easy.

There are extensions to git, like git submodule and git subtree in which you can "mount" another git repo at a specific version in a master repo. In that case you could merge between branches of the same repo.

Another option is to have multiple forks of the same repo and to merge between the forks. As long as these forks are created from the same master repo, you can merge the contents of the repo between branches of these forks.

There are also tools like gita that can help you manage a folder structure locally that checks out multiple repositories locally and have them be at different versions/branches/tags.

In all of these cases you'll end up with multiple repositories that contain the things you want to version. And then a master repo or configuration that wraps around it.

When creating multiple repositories in Azure Repos, you can either do this using the fork feature to create a merge-compatible copy of the repo. When it's a true fork, Azure Repos will allow you to pull-request between them.

Or you can git clone the repo from repo A and then push that into repo B to allow merges between them. You would then have to do the merges in a local repository that has multiple remotes attached to it.

英文:

A plain git repo can't do this really... But you can accomplish similar scenarios in git, but it's not easy.

There are extensions to git, like git submodule and git subtree in which you can "mount" another git repo at a specific version in a master repo. In that case you could merge between branches of the same repo.

Another option is to have multiple forks of the same repo and to merge between the forks. As long as these forks are created from the same master repo, you can merge the contents of the repo between branches of these forks.

There are also tools like gita that can help you manage a folder structure locally that checks out multiple repositories locally and have them be at different versions/branches/tags.

In all of these cases you'll end up with multiple repositories that contain the things you want to version. And then a master repo or configuration that wraps around it.

When creating multiple repositories in Azure Repos, you can either do this using the fork feature to create a merge-compatible copy of the repo. When it's a true fork, Azure Repos will allow you to pull-request between them.

Or you can git clone the repo from repo A and then push that into repo B to allow merges between them. You would then have to do the merges in a local repository that has multiple remotes attached to it.

答案2

得分: 1

经过尝试了jesse建议的解决方案并调查了各种不同的其他方法,我得出结论,没有简单的方法可以像TFVS那样合并不同的文件夹分支。

我将写下对我有效的方法,以防其他人也遇到类似的问题,尽管这个方法对我来说略显手动。

首先,我下载了一个名为"Meld"的Windows开源比较工具:

https://meldmerge.org/

使用Meld,我比较了文件夹A和文件夹B,显示了两个文件夹之间的所有更改,包括所有文件,并使用GUI复制了所需的所有内容。

Meld的好处是它允许我通过点击按钮复制更改,而不必手动复制粘贴所需的内容。

虽然它不像TFVS那样快(TFVS"智能知道"文件之间的主要差异是什么,只显示了合并冲突),但由于对我来说易于使用,这是一个接近的第二选择。

英文:

After trying the solutions suggested by jesse and investigating various different other methods, I've come to the conclusion that there is no easy way to do what TFVS was able to do with merging different folder branches.

I'll write down what has worked for me incase someone else also stumbles onto a similar issue as this as it's working for me (albeit slightly more manual than I'd like).

First, I downloaded a Open Source comparison tool for Windows called "Meld":

https://meldmerge.org/

Using Meld, I compared Folder A with Folder B which showed every changes between the two folders including all files and copied everything needed across using the GUI.

The benefits with Meld was that it allowed me to copy over changes with a click of a button instead of having to manually copy pasting what I wanted.

While it's not as fast as TFVS (which "intelligently knew" what the main differences were between the files and only showed me merge conflicts) this comes at a close second due to the ease of use for me case.

huangapple
  • 本文由 发表于 2023年4月20日 07:36:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定