仅从特定文件夹进行 Git 合并

发布于 2024-08-09 12:19:13 字数 467 浏览 1 评论 0原文

我已经为客户 X 创建了一个 Rails 网站。我现在有一个客户 Y,他想要一个与客户 X 执行完全相同的操作但具有不同外观的网站。

我从 clientXcode 创建了一个 git 分支,并将其命名为 clientYcode。然后我对视图进行了所有更改,使其看起来不同,拉拉,同一个网站,但皮肤不同。

现在,我对 git 不明白的地方是:我对 clientXcode 的视图、模型和控制器做了很多更改;现在我想将这些更改合并到 clientYcode 中,不包括任何视图更改。由于视图、模型和控制器在 Rails 中都有自己的文件夹,因此我希望能够执行以下操作:

git merge client_x_code 'app/controllers/*', 'app/models/*'

问题 1:使用 git 可以实现类似的操作吗?如果是这样,我该怎么做?

问题 2:分支是复制我的项目的最佳解决方案吗?

I've created a rails website for client X. I now have a client, Y, who wants a website that does the exact same thing as client X, but with a different skin.

I made a git branch from clientXcode and called it clientYcode. I then did all the changes to the views to make it look different, and lala, the same website with a different skin.

Now here's what I don't understand about git: I've made many changes to clientXcode in the views, models, and controllers; and now I want to merge those changes into clientYcode, excluding any view changes. Since views, models, and controllers each have their own folder in rails I was hoping to be able to do something like:

git merge client_x_code 'app/controllers/*', 'app/models/*'

QUESTION 1: Is something like that possible with git? If so, how would I do it?

QUESTION 2: Was branching the best solution to make a copy of my project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸印温柔 2024-08-16 12:19:13

好吧,我找到了解决我的问题的最简单的解决方案......

git checkout clientYcode
git checkout clientXcode "app/controllers/"
git checkout clientXcode "app/models/"

这就是我想要的!

Well I found the easiest solution to my problem...

git checkout clientYcode
git checkout clientXcode "app/controllers/"
git checkout clientXcode "app/models/"

And that does what I want!

屋檐 2024-08-16 12:19:13

最简单的做法是合并除要保留的目录内容之外的所有内容。
您可以通过在该目录中添加合并驱动程序来做到这一点,如 如何告诉 git 始终选择本地版本来进行特定文件上的冲突合并? 问题详细信息。

有了合并驱动程序,分支在这种情况下是一个很好的解决方案。


提炼:

我们在 dirWithCopyMerge 目录中定义了一个 .gitattributes 文件(仅在发生合并的分支中定义:myBranch),我们有一个 .git\config 文件,它现在包含一个合并驱动程序。

[merge "keepMine"]
        name = always keep mine during merge
        driver = keepMine.sh %O %A %B

The simplest course of action is to merge everything, except the content of the directory you want to keep.
You can do that by adding a merge driver in that directory, as the How do I tell git to always select my local version for conflicted merges on a specific file? question details.

With that merge driver in place, Branching is a good solution in this case.


Extract:

We have a .gitattributes file defined in the dirWithCopyMerge directory (defined only in the branch where the merge will occurs: myBranch), and we have a .git\config file which now contains a merge driver.

[merge "keepMine"]
        name = always keep mine during merge
        driver = keepMine.sh %O %A %B
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文