从分支的Git签出文件,而不更改索引 [英] Git checkout file from branch without changing index

查看:77
本文介绍了从分支的Git签出文件,而不更改索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git开发中,我使用以下checkout命令结构将来自其他分支的单独文件引入到我的工作目录中.

In my git development I am using the following checkout command structure to bring in solitary files from other branches into my working directory.

git checkout [<tree-ish>] [--] <pathspec>…​

根据文档,这也将文件更新为我的索引,就好像我要提交该文件一样-如果我不想提交该文件,则剩下了从索引中删除它的额外步骤. (我们正在使用二进制文件进行开发:(并且这种工作方式有助于测试我们的个人工作,该工作可能与另一位并行工作的开发人员的工作有关)

As per documentation, this also updates my index with the file as if I wanted to commit it - leaving me with the extra step of deleting it from my index if I don't want to commit the file. (We're doing development with binary files :( and this way of working is helpful for testing our individual work that may relate to the work of another developer that's working in parallel)

是否有任何方法可以从分支/提交中拉出/签出单个文件,从而更新工作目录而不是索引?

Is there any way to pull/checkout a singular file from a branch/commit such that it updates the working directory and NOT the index?

我想我可以将这两个步骤混为一个命令,但是我很好奇是否已经有一个(单个)git命令能够完成此任务.

I figure I could alias the two steps into a single command, but I'm curious if there is already a (single) git command capable of accomplishing this.

推荐答案

另一种方法是

git show otherBranch:fileName > fileName

这将创建一个新文件,文件的内容在另一个分支中

This creates a new file with the content of the file in the other branch

无论如何,如果您的工作流程需要经常执行此步骤,我会创建一个别名

Anyway if your workflow requires this step to be done often, I would create an alias

这篇关于从分支的Git签出文件,而不更改索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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