如何应用合并到一个分支,而不是在它?



我想在另一个分支上合并到我的分支

输入图片描述

我这样做了:

$ git fetch origin dev/FW-5116_hw_monitor_multi_platform:tst/QA-1641_voltage_monitor

和我得到这样的消息:

fatal: refusing to fetch into branch 'refs/heads/tst/QA-1641_voltage_monitor' checked out at 'C:/workspace/OM/lidar-fw'
fatal: the remote end hung up unexpectedly

实际上,你已经问了两个独立的问题:

问:我怎么能合并到一个分支,而不是在分支上?
这个问题的答案很简单:"你不能"——至少,从现在的Git版本(2.38.1)开始不能。目前,merge总是对当前分支进行操作。有一些特殊的事情,包括你正在尝试做的事情,不是git merge

Q:这里的错误信息是什么意思?

fatal: refusing to fetch into branch
'refs/heads/tst/QA-1641_voltage_monitor' checked
out at 'C:/workspace/OM/lidar-fw'

这是指您尝试使用专用的非合并git fetch操作:

git fetch origin dev/FW-5116_hw_monitor_multi_platform:tst/QA-1641_voltage_monitor

中与

git worktree add的组合。也就是说,您之前使用git worktree add在目录C:/workspace/OM/lidar-fw中创建了分支名称tst/QA-1641_voltage_monitor的本地签出。Git知道——或者至少相信——这个本地签出仍然存在。

您有几个选项来解决第二个问题:

  • 删除添加的工作树,例如使用git worktree remove(确保在删除之前保存任何未保存的工作!);
  • 如果添加的工作树已经被删除,使用git worktree prune通知Git,假设添加的工作树也没有被锁定(参见git worktree文档);
  • 使用添加的工作树,在处运行获取并合并操作

例如,使用bash shell,您可以运行:

pushd /C/workspace/OM/lidar-fw
git fetch
git merge origin/dev/FW-5116_hw_monitor_multi_platform
<finish the merge if necessary>
popd

或者,没有bash和pushd/popd,您可以使用您喜欢的任何shell打开一个单独的窗口,并将您的工作目录更改为C:/workspace/OM/lidar-fw(这可能是我最初这样做的方式)。

最新更新