简体   繁体   English

在没有任何工作树的情况下使用Git

[英]Using Git without ANY working tree

Suppose you have a bare repository. 假设您有一个裸仓库。 It contains 3 files: 它包含3个文件:

  • a.txt
  • b.txt
  • c.txt . c.txt

Now, suppose I don't have the b.txt and c.txt but I have a newer version of the a.txt file. 现在,假设我没有b.txtc.txt但是我有a.txt文件的较新版本。 Is it possible to use some command in git and tell it to Update a.txt in the repository, without having to clone/pull the other files? 是否可以在git中使用某些命令并告诉它更新存储库中的a.txt ,而无需克隆/拉出其他文件? Something like: "Update a.txt in that repository and only look for changes in files that already exist." 诸如此类: “更新该存储库中的a.txt ,仅查找已经存在的文件中的更改。” If not, is there any other version control system which supports this? 如果没有,是否还有其他支持此功能的版本控制系统?

Update: 更新:

One example for this would be this: A website like github, containing a lot of repositories and a lot of files in each repository. 例如:像github的网站,其中包含很多存储库,每个存储库中都有很多文件。 Only, in this website users won't always see the latest revision. 仅此网站的用户不会总是看到最新的修订版。 They select a revision to see and sometimes they would want to update a file. 他们选择要查看的修订版本,有时他们想要更新文件。 In this case, the total size of the files would be too much. 在这种情况下,文件的总大小将太大。 Considering the users won't always see the latest revision, I think a better way would be to just get a single revision of a particular file on demand and whenever an update is added, add the updated files. 考虑到用户不会总是看到最新的修订版,我认为更好的方法是按需获取特定文件的单个修订版,并且每当添加更新时,都添加更新的文件。

Subversion can do what you want. Subversion可以做您想要的。 And for git, there's a similar question: Pull single file on server 对于git,还有一个类似的问题: 在服务器上提取单个文件

You can not that without a copy of the repository – that's just the way git works. 没有存储库的副本,您不可能做到这一点– git就是这样工作的。 If you want to do stuff to the repository without full access to a full copy of it, git is not the right tool for you. 如果您想在没有完全访问存储库的完整副本的情况下对存储库进行操作,则git不是适合您的工具。 But as I understood from your comments, you do have the repository on your server, and that's actually where you want to do all the work. 但是据我从您的评论中了解到,您的服务器上确实有存储库,实际上这是您要完成所有工作的地方。 You just don't want to do a full checkout to touch only a single file. 您只是不想进行完整的签帐以仅触摸单个文件。

If that's correct, you are looking for a for a feature that's called “sparse checkout” in git and is available since 1.7. 如果正确,则您正在寻找git中称为“稀疏签出”的功能,该功能自1.7开始可用。 For more details, see my answere here: How do I clone a subdirectory only of a Git repository? 有关更多详细信息,请在此处查看我的回答如何仅克隆Git存储库的子目录? (this question was about sub-directories, but works exactly the same way for single files) (这个问题是关于子目录的,但是对于单个文件的工作方式完全相同)

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

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