在Git中只能拉一个文件吗? [英] Is it possible to pull just one file in Git?

查看:125
本文介绍了在Git中只能拉一个文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个Git分支,它有一些破损的测试,我想从另一个分支已经修复的地方抽取(合并更改,而不是覆盖)这些测试。



我知道我可以做的

  git pull origin that_other_branch 

但是这会尝试合并很多其他文件,因为我还没准备好。



是否可以从另一个分支中仅抽取和合并指定的文件(而不是所有文件)?



这不是 Git只需要一个文件的请求 作为所有问题的答案是如何将本地更改的文件恢复到存储库版本,而不更改任何分支。 您可以获取然后签出只有一个文件是这样的:

  git fetch 
git checkout -m <修改> < yourfilepath>
git add< yourfilepath>
git commit

关于 git checkout code>命令
< revision> - 分支名称,即 origin / master
< yourfilepath> 不包括存储库名称(点击 copy path 按钮),即 README.md


I am working on a Git branch that has some broken tests, and I would like to pull (merge changes, not just overwrite) these tests from another branch where they are already fixed.

I know I can do

git pull origin that_other_branch

but this will attempt to merge lots of other files, for that I am not yet ready.

Is it possible to pull and merge only the specified file (and not everything) from that another branch?

This is not a duplicate of Git pull request for just one file as all answers to that question are how to revert the locally changed file to the repository version, without changing any branches.

解决方案

You can fetch and then check out only one file in this way:

git fetch
git checkout -m <revision> <yourfilepath>
git add <yourfilepath>
git commit

Regarding the git checkout command: <revision> - a branch name, i.e. origin/master <yourfilepath> does not include the repository name (that you can get from clicking copy path button on a file page on GitHub), i.e. README.md

这篇关于在Git中只能拉一个文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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