首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >有没有可能在Git中只拉取一个文件?

有没有可能在Git中只拉取一个文件?
EN

Stack Overflow用户
提问于 2013-04-26 15:20:24
回答 3查看 318.3K关注 0票数 212

我正在一个Git分支上工作,它有一些损坏的测试,我想从另一个已经修复的分支中拉出(合并更改,而不仅仅是覆盖)这些测试。

我知道我能做到

代码语言:javascript
复制
git pull origin that_other_branch

但这将尝试合并许多其他文件,为此,我还没有准备好。

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

这不是的副本,因为该问题的所有答案都是如何将本地更改的文件恢复到存储库版本,而不更改任何分支。

EN

回答 3

Stack Overflow用户

发布于 2014-08-23 06:50:51

这是我在研究这个问题时想出的一个稍微简单一点的方法:

代码语言:javascript
复制
git fetch {remote}
git checkout FETCH_HEAD -- {file}
票数 254
EN

Stack Overflow用户

发布于 2019-02-04 02:19:22

@Mawardy的答案对我有效,但我的更改是在遥控器上进行的,所以我必须指定来源

代码语言:javascript
复制
git checkout origin/master -- {filename}
票数 30
EN

Stack Overflow用户

发布于 2019-07-08 15:54:09

可以,流程如下:

代码语言:javascript
复制
# Navigate to a directory and initiate a local repository
git init        

# Add remote repository to be tracked for changes:   
git remote add origin https://github.com/username/repository_name.git

# Track all changes made on above remote repository
# This will show files on remote repository not available on local repository
git fetch

# Add file present in staging area for checkout
git check origin/master -m /path/to/file
# NOTE: /path/to/file is a relative path from repository_name
git add /path/to/file

# Verify track of file(s) being committed to local repository
git status

# Commit to local repository
git commit -m "commit message"

# You may perform a final check of the staging area again with git status
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16230838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档