Git checkout file from branch without changing index

南楼画角 提交于 2019-12-23 08:56:50

问题


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?


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.


回答1:


Another way would be

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



来源:https://stackoverflow.com/questions/50158417/git-checkout-file-from-branch-without-changing-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!