git - 我可以为多个不同的本地位置拥有一个存储库吗

标签 git bitbucket sourcetree

在 Bitbucket 上我有多个存储库,其中一个是通用存储库(如库)

我有多个项目使用同一个存储库。目前每个项目都有不同的 sourcetree 存储库链接到 Bitbucket 上的同一个存储库,我想知道是否可以为我的计算机上的多个不同位置只创建一个 sourcetree 存储库。

例如:

I have 3 projects call them A, B & C
On Bitbucket I have 5 repositories call them (AA, BB, CC, DD, General)
What I have is
Project A need AA, BB & General
Project B need CC & General
Project C need DD & General

我想知道在 sourcetree 中我是否只能创建 1 个链接到 3 个不同位置的 3 个项目的存储库,或者是否只能使用一个位置并且我必须为每个项目创建 3 个 sourcetree 存储库。

感谢您的回答。

最佳答案

... one sourcetree repository for multiple different location on my computer.

是的,你可以。

您必须使用 git v2.5 及更高版本,然后您可以使用 git worktree

Git worktree 于 2007 年在 git repo 的 contrib 文件夹下引入,名为 new-workdir


git worktree

例如:

git worktree add <second path>

将在您的计算机上创建另一个文件夹,允许您同时在不同的分支上工作。

git worktree 将创建 2 个彼此分开的独立工作文件夹,同时指向同一个存储库。

这将允许您在新工作树上进行任何实验,而不会对存储库本身产生任何影响。在所附的图片中,您可以看到有 2 个独立的 工作文件夹,但它们都使用一个存储库并共享内容。

这是一个关于如何创建新工作树及其结果的示例:

enter image description here

关于git - 我可以为多个不同的本地位置拥有一个存储库吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37964822/

相关文章:

git - 在 GitHub 上查看没有空格更改的提交

git - SourceTree 不显示同事的远程分支

git checkout 后 Git 丢失本地提交文件

atlassian-sourcetree - 在 Sourcetree 中创建分支组

git - Sourcetree 中的 .gitignore 文件不起作用

node.js - 开发流程中的 Git npm 版本管理

git - 在多个 Visual Studio Team Services 项目之间共享一个 git 存储库

混帐 "discrepancy": `git diff` does not take commit messages into consideration but SHA-1 generation takes commit messages while computing SHA-1

git - 如果分支提交了具有特定条件的消息,则防止 merge 到 master

tortoisehg - 如何将 bitbucket.org 的问题与 TortoiseHg 中的问题跟踪集成?