Git - 如何从单个分支中删除文件
我有一个存储库,我有一个主分支,最终将包含该应用程序的“核心”,以及将包含核心的客户端分支,以及包含所有资产、样式和前端视图的公共侧。我知道这是可以完成的,因为我已经用本地存储库对其进行了测试。但问题是我从一个完全构建的客户端应用程序开始,我想从主分支中切出一些文件夹,当我向外合并到客户端分支时,不将这些删除传播到其他分支,更新为系统的核心。
因此,用更简单的术语来说,如何从一个分支中删除文件,而不在合并时将该删除传播到其他分支?
I have a repo that I have a master branch which will end up containing the "core" of this app, and client branches that will contain the core, and additionally the public side that contains all the assets, styling, and front-end views. I know this can be done as I have tested it with a local repo. BUT the problem is I'm starting from a fully built out client app, I'm wanting to carve out a few folders from the master branch w/o propogating those deletes to other branches when I merge outward to the client branches, updates to the core of the system.
So, in more simple terms, How do I remove a file from one branch without propogating that delete to other branches upon a merge?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
IMO,您应该使用 子模块 来分隔客户端细节(资产等)。手动处理这个问题会引发灾难。
为每个客户端创建一个单独的存储库,并添加一个指向您的核心的子模块,以及它们之间共享的任何其他内容。不在客户端之间共享的代码不需要属于核心,也不需要属于其他共享子模块。这意味着与客户端对应的每个(当前)分支必须成为一个单独的存储库。毕竟,它们是相互独立的,这就是重点。
您最终将得到以下存储库层次结构:
更新:
重要:备份所有内容,这样在出现问题时就不会遇到麻烦。
所有这些都高度取决于您的场景。但以下是如何在非 Windows 系统中完成我所描述的内容的想法:
1) 将当前存储库拆分为各种存储库(例如:core、client1、client2 等):
重复此操作对于每个客户端目录也是如此。在此步骤结束时,您将为每个部分(核心、客户端 1、客户端 2 等)拥有一个单独的存储库。
2) 将新的拆分核心存储库作为子模块添加到每个 client1..clientN 存储库中:
3) Coffee &利润。
IMO you should use submodules to separate client specifics (assets, etc). Manually dealing with that is an invitation to disaster
Create a separate repository for each client, and add a submodule pointing to your core, and for anything else that is shared between them. Code that isn't shared between clients doesn't need to belong to the core, nor to other shared submodules. It means each (current) branch corresponding to a client has to become a separate repository. After all, they're independent of each other, and that's the whole point.
You'll end up with this repository hierarchy:
UPDATE:
IMPORTANT: backup everything so you don't get into trouble if something goes wrong.
All this is highly dependent on your scenario. But the following is an idea of how to accomplish what I described in a non-Windows system:
1) Split your current repository into various repositories (e.g.: core, client1, client2, etc):
Repeat this for each client directory too. At the end of this step, you'll have a separate repository for each of these parts (core, client1, client2, etc).
2) Add the new split core repository as a submodule to each of your client1..clientN repositories:
3) Coffee & profit.
您可以删除 banche 中的文件,但您可以将“core” banche 与已删除的文件合并到您的分支中,而不是将您的分支合并到“Core”中。这样它们将始终保持同步,但您删除的任何文件只会在指定的分支中删除。
You can delete the file in the banch, but instead of merging your branch into the "Core", you can mege the "core" banche INTO your branch with the deleted file. This way they will always be in sync, but any files you delete will only be deleted in the branches specified.
我不是 git 用户,但一般来说,我相信您应该能够从主干中删除文件,然后在从主干合并到分支期间,撤消该更改(例如,保留或恢复工作副本中的文件) )然后提交合并。变更集应该被视为已在未来合并中合并到分支中。
I'm not a git user, but generically speaking, I believe you should be able to delete the file from the trunk and then during the merge from trunk to the branch, undo that change (e.g. keep or restore the file in the working copy) and then commit the merge. The changeset should be seen as merged into the branch already in future merges.
我最终只是为核心创建了一个新的存储库,并重新创建了客户端分支,因为这个结构是事后才想到的。所以我试图向后做这件事。
I ended up just creating a fresh repository for the core, and remaking the client branches, as this structure was an afterthought. So I was trying to do this backwards.