2

Suppose you have a bare repository. It contains 3 files:

  • a.txt
  • b.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. 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? Something like: "Update a.txt in that repository and only look for changes in files that already exist." 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. 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.

Community
  • 1
  • 1
Alireza Noori
  • 14,961
  • 30
  • 95
  • 179
  • 1
    Please explain the reason why you do not want to clone/pull. Are you concerned of memory consumption or bandwith problems or ...? It is in the nature of git that you get the whole history if you want to work with it. – Nobody moving away from SE Dec 23 '12 at 10:39
  • Theoretically, I think doing this should be possible: you don't need all the files to create a new commit, just their SHA1s (or, more precisely, the `tree` object) and the SHA1 of the parent commit. Practically, I doubt there is a tool that can do this. – svick Dec 23 '12 at 10:57
  • @Nobody Please read the update to see an example. What do you think? – Alireza Noori Dec 23 '12 at 12:02
  • I am not sure if I understood your example correctly. Are the users changing their files online or checking them out locally? Git allows to check out single files of only one revision (so no history, the parameter was `--depth` if I remember correctly) but without the history pushing and merging is not possible. @svick Sure it is possible to do so but I think likewise that standard git will not be able to. – Nobody moving away from SE Dec 23 '12 at 12:25
  • 2
    Also note that the example you describe (or I understood) does look very centralized. As git is a distributed VCS it may be the wrong tool for the task. SVN is centralized and would fit better (although that is just by word meaning, as I am no expert in SVN usage). – Nobody moving away from SE Dec 23 '12 at 12:31
  • @Nobody Yes, users update the files online and no checkout is allowed. I use version control internally. I have previously used SVN but I read that Git has some performance advantages. If that's the case, I'll switch to Git. Performance is **VERY** important to me. – Alireza Noori Dec 23 '12 at 12:45
  • As it seems your repository and the working copy are on the same machine. Then you could also spare the bare repo and use a non bare repo instead where you do all the actions. You would not have to store the history twice and could let the user work with the files in the repo directly. – Nobody moving away from SE Dec 23 '12 at 13:24
  • @Nobody As I mentioned in the example I don't want to keep the files. They'll keep so much space. In my SVN version I only create the file, update it in repo and delete it. – Alireza Noori Dec 23 '12 at 14:31

2 Answers2

4

Subversion can do what you want. And for git, there's a similar question: Pull single file on server

Community
  • 1
  • 1
Hvordan har du det
  • 3,605
  • 2
  • 25
  • 48
  • Could you please tell me how to do it in SVN? And if I use the method in the post you linked, should I delete the local repository each time? – Alireza Noori Dec 23 '12 at 10:29
  • Suppose you have a SVN repo, simply `svn update a.txt` will do. – Hvordan har du det Dec 23 '12 at 10:38
  • I think using the `git fetch && git check -m revision -- the/file/you/want` way inside a non-bare git repo won't needs you deleting any local repositories (but like @Nobody says, it might not be the right way to use git). Furthermore, you're using a bare repository, I'm not familiar with that and have no idea how to do what you want with it. – Hvordan har du det Dec 23 '12 at 10:52
  • Thanks. I just remembered. In my previous release, I used the exact command. I read in a lot of places that Git is better than SVN so I wanted to move to Git. What do you think? Should I move? It seems that maybe for my project maybe SVN is better? (please read the updatad question) – Alireza Noori Dec 23 '12 at 12:05
1

You can not that without a copy of the repository – that’s just the way git works. 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. 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. For more details, see my answere here: How do I clone a subdirectory only of a Git repository? (this question was about sub-directories, but works exactly the same way for single files)

Community
  • 1
  • 1
Chronial
  • 66,706
  • 14
  • 93
  • 99