如何在一个 GIT 存储库中跟踪项目的两个版本?
我在一个本地 git 存储库中有一个项目的两个版本。我必须将此存储库提交到 2 个远程存储库,每个版本一个;
本地 GIT(V1/V2) ->远程 GIT(V1)、远程 GIT(V2)
我在本地 GIT 存储库中有一些文件,这些文件应该只转到远程 GIT(V1),其他文件应该只转到远程 GIT(V2)。现在我将完整的本地存储库提交到两个遥控器。 我可以只提交一些文件到 REMOTE1 吗?
我需要在一个存储库中拥有该项目的两个版本,但希望有一个选项可以稍微划分历史记录。我认为任何分支都没有帮助,因为那样我就必须对两个分支进行相同的更改。 VER 1 和 VER 2 的大部分代码(90%)是相同的。两个版本的新代码通常是相同的。
I have two versions of one project in one local git repository. I have to commit this repository into 2 remote repositories, one for each version;
LOCAL GIT(V1/V2) -> REMOTE GIT(V1), REMOTE GIT(V2)
I have some files in the LOCAL GIT repository which should only go to REMOTE GIT(V1) and other should only go to REMOTE GIT(V2). Now I commit full local repository to both remotes.
Can I only commit some files to REMOTE1?
I need to have both version of the project in one repository, but would like to have an options to divide history a bit. I do not think that any branching can help as then I would have to make the same changes to both branches mostly. Most of the code, 90% of the code is the same for VER 1 and VER 2. New code is usually the same for both versions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
分支正是您所需要的。使用 Git 进行分支既简单又快速,因此除了多敲几下键盘之外,您不会丢失任何东西。
您可以使用 3 个分支。创建一个“通用”分支,您将在其中处理两个“分支”通用的内容,并在提交后合并到它们中。对于特定的事情,请在其中一个分支机构工作。
Git 在文件系统上使用硬链接,因此分支在速度和使用空间方面都很便宜。最后,您始终可以选择要推/拉的分支。
Branching is exactly what you need. Branching is easy and very quick with Git, so you don't lose anything but a few more keystrokes.
You can use 3 branches. Create a "common" branch where you'll work on stuff common to both "forks" and merge into them after commits. For specific stuff, work in one of the branches.
Git uses hard links on the filesystem sobranches are cheap both in terms of speed and used space.Finally, you can always select which branch to push/pull.
创建三个 Git 存储库:
core
、app_1
、app_2
。在每个app
存储库中,创建一个引用core
存储库的 Git 子模块。将
core
存储库视为纯库,将app
存储库视为纯库使用者,构建这三个项目,以便您可以将两个“版本”的所有共同内容保留在core
存储库以及app
存储库中两个版本之间存在差异的所有内容。构建app
存储库,以便可以将core
项目无需修改地批量放置到app
存储库内的子目录中。您可能需要在所有app
存储库之间共享一个最小的通用初始化脚本,但这是一个很小的代价。以这种方式构建代码的场景非常常见。尽管以这种方式使用 Git 来支持这种代码架构场景的情况要少得多,但它被视为一种可行的可能性。
Create three Git repositories:
core
,app_1
,app_2
. Within each of theapp
repositories, create a Git submodule referencing thecore
repository.Treat the
core
repository as a pure library and theapp
repositories as pure library consumers, structuring the three projects such that you can keep everything common to the two "versions" in thecore
repository and everything that would diverge between the two versions in theapp
repositories. Structure theapp
repositories such that thecore
project can be placed wholesale, with no modifications, into a subdirectory within theapp
repositories. You may require a minimal common initialization script shared between allapp
repositories, but that is a small price to pay.The scenario of structuring the code this way is very common. Although using Git in this way to support this code architecture scenario is far less common, it is seen as a viable possibility.
听起来您需要使用子模块
git-submodule
。您可以将公共代码存储在主存储库中,然后将单独的版本存储在子模块中。你不能用 git 分割历史记录。每个提交都是基于内容和父项以加密方式进行的。Sounds like you need to be using submodules
git-submodule
. You would store the common code in the main repository, but then store the separate versions in submodules. You can't split history with git. Each commit is cryptographically based on content and parents.