将分支中的文件检出到该文件不存在的工作分支中

checkout files from a branch into working branch where this files don't exist

我有一个分支 (feature-4),我想在其中添加子文件夹 (src/peripherals/dma) 中的所有文件,这些文件在另一个分支 (feature-5) 中提交。

签出的分支是 feature-4,不包含文件夹 src/peripherals/dma(src/peripherals 确实存在)

我的一位同事确实将用于 dma 的代码推送到他的 feature-5 分支中。

如 git checkout 的手册和此 link (jasonrudolph.com) git checkout 中所述应该这样做,但既不提供文件路径也不提供文件夹路径做了工作。

$ git branch
* feature-4
  feature-5
  master

$ git checkout feature-5 src/peripherals/dma/dma_config.c
error: pathspec 'src/peripherals/dma/dma_config.c' did not match any file(s) known to git

daimonion@ZBOOK-004 MINGW64 ~/K4G1/src/peripherals/dma (feature-4)
$ ls -al
total 4
drwxr-xr-x 1 daimonion 1049089 0 Sep  4 09:13 ./
drwxr-xr-x 1 daimonion 1049089 0 Sep  4 09:13 ../
-rw-r--r-- 1 daimonion 1049089 0 Sep  4 09:13 dma_config.c

我认为 git 有问题,因为该文件不存在,但即使我向分支 feature-4 提交一个空的 dma_config.c,它也会给出同样的错误。

怎么可能 git 到 "merge" 一些文件从一个分支到另一个不存在的分支?

提前致谢

问候 daimonion

这应该不是问题,您可以很好地从另一个分支签出文件,即使它不存在于当前分支。

一个可能的原因可能是您的本地版本 feature-5 不是最新的(因此还没有带来所需文件的提交),请确保

git checkout feature-5
git pull

在重试您的命令之前。


此外,路径规范应该在 -- 之前,所以

git checkout feature-5 -- src/peripherals/dma/dma_config.c