我会用git-worktree来做什么? [英] What would I use git-worktree for?

查看:124
本文介绍了我会用git-worktree来做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 Github在git-worktree上的帖子。他们写道:

lockquote

假设你在名为特性 master 中的紧急程度错误时。首先,您创建一个带有新分支的链接工作树, hotfix ,相对于master [...]签出。您可以修复该bug,推送修补程序并创建拉取请求。


当我在一个叫做feature的分支上工作,并且报告了master中的一些高度紧迫性的bug时,我通常会隐藏任何正在努力并创建一个新的分支。完成后,我可以继续工作。这是一个非常简单的模型,我一直在努力工作多年。



另一方面,使用git-worktree有其自身的局限性:


例如,不允许同时在两个链接的工作树中检出同一分支,因为这样可以在一次工作中提交更改让另一个不同步。


为什么我会为已经解决的问题选择更复杂的工作流? / p>

是否有任何关于 git-worktree 的事情无法预先完成,并证明这是全新的,复杂的功能?

解决方案

对我来说,git worktree是很长一段时间以来最大的改进。我正在从事企业软件开发。在那里,你必须维护3年前发布的旧版本。当然,每个版本都有一个分支,这样您就可以轻松切换到它并修复一个错误。但是,切换很昂贵,因为在此期间,您完全重新构建了存储库并可能构建系统。如果切换,您的IDE将疯狂地尝试修改项目设置。



使用工作树,您可以避免持续的重新配置。使用工作树签出单独文件夹中的旧分支。对于每个分支,您都有一个独立的IDE项目。



当然这可以通过多次克隆repo来完成,这是我迄今为止的方法。然而,这也意味着浪费硬盘空间,而且更糟的是需要多次从回购库中获取相同的更改。



现在,唯一缺少的部分是官方的git 2.5版本Windows,但希望新的git for windows 即将发布: - )


I read Github's post on git-worktree. They write:

Suppose you're working in a Git repository on a branch called feature, when a user reports a high-urgency bug in master. First you create a linked working tree with a new branch, hotfix, checked out relative to master […] You can fix the bug, push hotfix, and create a pull request.

When I'm working on a branch called feature and some high-urgency bug in master is reported, I usually stash away whatever I'm working on and create a new branch. When I'm done, I can continue working. This is a very simple model, I've been working like that for years.

On the other hand, using git-worktree has its own limitations:

For example, it's not allowed to have the same branch checked out in two linked working trees at the same time, because that would allow changes committed in one working tree to bring the other one out of sync.

Why would I choose a more complicated workflow for a problem that's already been solved?

Is there anything about git-worktree that couldn't be done beforehand and that justifies this whole new, complex feature?

解决方案

For me, git worktree is the biggest improvement since a long time. I'm working in enterprise software development. There, it is very common that you have to maintain old versions like what you released 3 years ago. Of course you have a branch for each version so that you can easily switch to it and fix a bug. However, switching is expensive, because in the meantime you completely restructured the repository and maybe build system. If you switch, your IDE will run mad trying to adapt the project settings.

With worktree, you can avoid that constant reconfiguration. Checkout those old branches in separate folders using worktree. For each branch, you got an independent IDE project.

Of course this could have been done in the past by cloning the repo several times and this has been my approach so far. However, that also meant wasting hardrive space and worse needing to fetching the same changes from the repo several times.

Now, the only missing part is an official git 2.5 version for Windows, but there are hopes that the new git for windows is releasing soon :-)

这篇关于我会用git-worktree来做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆