使用单个git命令从另一个分支复制文件而无需提交

时间:2019-03-11 16:02:11

标签: git branch

可以在不提交目的地的情况下将文件从一个分支复制到另一个分支,例如:

if x = 1,
and y = 2,
then z should equal 12

但是,可以使用单个 $ git checkout otherbranch somefile $ git reset HEAD somefile 命令完成上述操作吗?

1 个答案:

答案 0 :(得分:1)

git cat-file --filters -p otherbranch:somefile > somefile

otherbranch:somefilesomefileotherbranch的斑点。

git cat-file -p打印Blob的内容。

> somefile用内容覆盖工作树中的somefile

正如@jthill所评论的那样,应使用--filters,以防配置了任何过滤器并影响somefilegit lfs是用例之一。