从git仓库中取出一个目录 [英] Pulling just one directory out of a git repo

查看:117
本文介绍了从git仓库中取出一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git repo,我想要做一个pull。我做了一个正常的 git pull ,没有任何问题。问题是我只想从回购协议中找出一个特定的目录。我的想法是,我可以使用这样的规则使用 .gitignore 文件:

  #Ignore所有文件
/
#除了我想要的
!/ temp

问题是这不起作用。这是正确的方式来做到这一点,或有更好的方式吗?

解决方案

git pull 获取并合并远程分支。

.gitignore 只能在本地使用,并且会隐藏匹配的条目以显示 git状态并通过 git add 添加到索引中。这不是你想要的。

你想做的是<远端分支> fetch 远程分支,并从中提取目录/文件需要。

  $ git fetch< remote> <分支> 
$ git checkout< remote> /< branch> - relative / path / to / file / or / dir

file / dir现在应该在您的分支并添加到索引。

I have a git repo that I want to do a pull from. I do a normal git pull with no problems. The issue is that I want just one certain directory out of the repo. My thinking was that I could use a .gitignore file with a rule like this:

#Ignore all files
/
#Except the one I want
!/temp

The problem is this doesn't work. Is that the right way to do it or is there a better way?

解决方案

git pull fetches and merges the remote branch.

.gitignore works only locally, and will hide matching entries from showing up on git status and being added to the index with git add. It's not what you want.

What you want to do, is fetch the remote branch, and from that, extract the dir/file you need.

$ git fetch <remote> <branch>
$ git checkout <remote>/<branch> -- relative/path/to/file/or/dir

the file/dir should now be in your branch and added to the index.

这篇关于从git仓库中取出一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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