How to pull a single file from a server repository in Git?

I am working on a site with a server running Git. I am using Git for deployment (not GitHub). This was set up prior to my involvement using a hook method, and I referred to this question and entered the commands below, but it didn't work.

So basically, how do I pull a single file from the server? For instance, if I wanted to update my local file index.php? git pull index.php?


It is possible to do (in the deployed repository):

git fetch
// git fetch will download all the recent changes, but it will not put it in your current checked out code (working area).

Followed by:

git checkout origin/master -- path/to/file
//git checkout origin/master -- path/to/file will checkout the particular file from the the downloaded changes (origin/master).

git fetch --all
git checkout origin/master -- <your_file_path>
git add <your_file_path>
git commit -m "<your_file_name> updated"

这假设你从原始/主文件中提取文件。


Try using:

git checkout branchName -- fileName

Ex: git checkout master -- index.php

链接地址: http://www.djcxy.com/p/37808.html

上一篇: Git中有哪些操作很难/无法撤消?

下一篇: 如何从Git的服务器库中获取单个文件?