问题
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