Git只获取一个目录 [英] Git fetch only one directory

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

问题描述

我有一个开发人员在一个文件夹上工作,另一个在另一个文件夹上工作.我想用特定文件夹更新产品我正在寻找类似的命令:

I have a developer that works on one folder and another that works on another. I would like to update the production with a specific folder I'm looking for a command like:

cd /myproject
git pull myfolder

并期望只有 myfolder 会被更新

and expect that only myfolder will be updated

有可能吗?

好的,我会改写...我有一个项目,一个分支,两个开发人员和项目中有两个文件夹.每个开发人员都在一个文件夹上工作.两者都进行更改并将它们推送到分支中.

ok, i'll rephrase... I have one project, one branch and two developers and two folders in the project. each developer works on one folder. both make changes and push them into the branch.

我只想将一个文件夹的更改提取到我的本地计算机中

I want to pull only changes of one folder into my local machine

基本/简单不是吗?

推荐答案

假设你真正想要的是从 git 远程抓取文件存储库,没有您自己的工作树(或本地存储库),您可以这样做:

Assuming what you're really asking is to remotely grab files from a git repository, without having a working tree of your own (or a clone of the repository locally), you could do this:

git archive --format=tgz --remote=<url-to-repo> master -- myfolder | tar zxvf -

这表示要创建存储库主分支的压缩 tar 球住在 ,但只包含 myfolder 下的内容.通过 tar 管道将取消归档数据并将其放入当前工作目录.

This says to create a gzipped tar ball of the master branch of the repository living at <url-to-repo>, but include only the contents under myfolder. Piping that through tar will unarchive the data and put it in the current working directory.

如果您实际上是在尝试管理工作树并与其他两个树一起工作开发人员,那么您要求做的事情确实违背了工具.但是你必须更详细地说明你想要做什么完成以便有人提出好的工作流程建议.

If you're actually trying to manage a working tree and work with the other two developers, then what you're asking to do really goes against the grain of the tool. But you'd have to be much more elaborate about what you're trying to accomplish in order for someone to make a good workflow suggestion.

更新:

所以听起来好像您只想获取托管文件夹中的一个文件夹的更改工作树.抱歉,Git 不是这样操作的.正如我在下面的评论,Git 管理文件树.它不允许一部分树处于一个修订版,另一部分处于不同的修订版,例如你在暗示——也许你是以前的 Subversion 用户可能吗?

So it does sound as if you want to fetch just one folder's changes in a managed working tree. Sorry, but Git does not operate that way. As I said in the comments below, Git manages trees of files. It does not allow for part of a tree to be at one revision, and another part to be at a different revision like you're suggesting--perhaps you are a previous user of Subversion where this was possible?

你可以得到一个和你想要的差不多的效果,但是你必须修改你的工作副本.除非您愿意,否则我不会提交修改丢弃您的开发人员的一项工作.你可以这样做:

You can get an effect that is similar to what you want, but you have to modify your working copy. I would not commit the modification unless you want to discard one of your developers work. You could to this:

$ git fetch
$ git checkout @{u} -- myfolder

git fetch 将使您的远程引用保持最新——它将获取来自服务器的最新信息.git checkout @{u} -- myfolder 将使myfolder 看起来像跟踪分支中存在的内容.这有两个后果:

git fetch will bring your remote references up to date--it will fetch the latest information from the servers. git checkout @{u} -- myfolder will make myfolder look like what exists in the tracking branch. This has two consequences:

  • 您没有本地分支上的所有更改(并且您不想要它们,所以没关系),并且

  • You do not have all the changes on your local branch (and you didn't want them, so that's okay), and

myfolder 将显示为正在修改,因为 myfolder 的内容有已使用远程存储库中可用的最新版本进行了更新,但它是与您当前的版本不同.

myfolder will show as being modified because the content of myfolder has been updated with the latest available from the remote repository, but it is not the same as your current revision.

要让您的工作副本恢复正常,请执行以下操作:

To get your working copy back to normal, do this:

$ git checkout -- myfolder

从那里,您调用按照通常的机制来获取您的分支与遥控器保持同步(可能是 git pull).

From there, you call follow your usual mechanism for getting your branch up-to-date with the remote (likely git pull).

但是,这可能不是您想要的操作方式.尽管有你的评论,用例无关紧要",它确实很重要.往往有更好的实现总体目标和管理发展的方法,但它需要了解您正在尝试做什么.此刻,你提议确实违背了 Git 的预期工作方式.

This, however, is probably not how you want to operate. Despite your comment, "doesn't matter the use case", it really does matter. There are often better ways to accomplish your overall goal and manage your development, but it requires understanding what you're trying to do. At the moment, what you propose really goes against how Git is intended to work.

所以让我为你准备一些东西.使用主题分支进行研究作为管理正在完成的开发工作的一种方式,而不是使用文件夹对于树中的每个开发人员.可以对分支进行清晰、合乎逻辑的更改并在您测试并批准将它们纳入生产时合并.

So let me put a few things out there for you. Research using topic branches as a way to manage the development work being done, rather than using folders for each developer in the tree. Clear, logical changes can be made on branches and the merged as you test and approve them for inclusion into production.

一个好的起点是这里.它本身包含相当多的信息,并且一些跟随链接到几种不同风格的 Git 工作流程.你想结束的地方是有一个提交代表您实际放入的版本生产,而不会破坏其他人为您所做的工作.理想情况下,您会以某种有意义的方式标记已投入生产的内容.

A good place to start is here. It contains a fair amount of information itself, and some follow on links to several different styles of Git workflows. The place where you want to end is where there is a commit that represents the version you actually put into production, without destroying the work that others are doing for you. Ideally, you'd tag what was pushed into production in some meaningful way.

我知道没有人喜欢听,但培训可能对您的情况很有帮助.GitHub 提供了一些免费在线课程以及其他一些资源.从经验来看,一旦你掌握了如何Git 工作并解决了它所解决的问题,您最终会得到一个更好的工作流程.

I know no one likes to hear it, but training may be very helpful in your case. GitHub offers some free online classes as well as several other resources. Judging from experience, once you grasp how Git works and the problems it solves, you'll end up with a much better workflow.

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

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