简体   繁体   English

Git从部分存储库中拉出?

[英]Git pull from partial repository?

I am trying to merge different versions of the same file in git for one of my projects. 我正在尝试为我的一个项目在git中合并同一文件的不同版本。 The only way git will let me do this is by branching the repo, modifying the file, and then pulling the branch into my master. git允许我执行此操作的唯一方法是分支存储库,修改文件,然后将分支拉入我的主服务器。 The only problem is, my project contains 100's of files and I only need this one. 唯一的问题是,我的项目包含100个文件,而我只需要一个文件。 Is there any way to pull from a branch containing only this file? 有什么方法可以从仅包含此文件的分支中提取? Every time I try to do this, it deletes all of the other files. 每次尝试执行此操作时,它都会删除所有其他文件。 Is there some other way I can accomplish the base task at hand? 我还有其他方法可以完成当前的基本任务吗?

The only problem is, my project contains 100's of files and I only need this one. 唯一的问题是,我的项目包含100个文件,而我只需要一个文件。

This shouldn't be a problem. 这不应该是问题。 Go ahead and 来吧

  1. Clone the entire branch with 100's of files. 用100多个文件克隆整个分支。
  2. Modify the single file of interest. 修改感兴趣的单个文件。
  3. Commit the new branch (with 100's of files, only one of which has changed). 提交新分支(包含100个文件,其中只有一个已更改)。
  4. Pull the new branch into the old one, merging on the way. 将新分支拉入旧分支,并合并。

It sounds horrible, but git does this sort of thing very efficiently. 听起来很可怕,但是git非常有效地完成了这种事情。

I'm not sure of what are you trying to accomplish, but it looks like your fears are based in the idea that if you branch all your files, you'll end up with many un-needed copies of the files in your repo. 我不确定您要完成什么工作,但是您的担心似乎是基于这样的想法:如果分支所有文件,则最终在存储库中会得到许多不需要的文件副本。 That's not true, as git internally is extremely efficient. 事实并非如此,因为git内部非常高效。 So, branch without any fear, git takes care of the rest. 因此,分支无任何恐惧,git负责其余的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM