views:

146

answers:

4

Hello,

The scenario:

  1. I make some changes in a single file locally and run git add, git commit and git push
  2. The file is pushed to the remote origin master repository
  3. I have another local repository that is deployed via capistrano with the "remote_cache" method from that remote repository
  4. Now I don't want to deploy the whole application but just update/checkout that single file.

Please, is this somehow possible with git? I wasn't able to find anything that would work nor was I able to figure it out. With svn I just did svn up file and viola.

I'll be glad for any help, thanks!

A: 

You can use git checkout on a single file, if I remember right. Here's a post with a little more detail: http://norbauer.com/notebooks/code/notes/git-revert-reset-a-single-file

Curtis
-1 This is incorrect. The checkout command doesn't "check out" from a remote repository in the conventional sense. It's used to perform a local operation on a cloned repository.
Noufal Ibrahim
A: 

It is not possible in GIT.

Just think how can GIT represent the history to you.

Adrian Shum
+2  A: 

Git doesn't work on individual files. I'm not aware of the remote_cache setting so I can't comment on that. However, in git, you have to clone the entire repository, make a change to a file(s), commit it (this is a local operation) and then push the changes back.

In your setup, you should be able to simply pull the changes from the master repository (call it M) to your capistrano deployed repo(call it B). I don't see why you're having the problem. If B is substantially different and you don't want to mess it up, you can add M as a remote to B and then cherry-pick the specific commits you're interested in (i.e. the update to the file you're talking about) into B. Would that work for you?

Noufal Ibrahim
Thank you! Well, I'm not interested in a particular commit as a whole, I'd just like to update single file to its HEAD revision (even if the whole commit contains more than just this single file) in the master branch from the remote origin. I think I'm just misinterpreting git with ideas from svn. I'll have to experiment with it a little bit more.
foresth
Git maintains snapshots of the filesystem (the repository) rather than individual file histories so your navigation can only be between these snapshots. Cf. http://progit.org/book/ch1-3.html
Noufal Ibrahim
+1  A: 

Hi,

What you can do is:

  1. Update your local git repo:

    git fetch

  2. Build a local branch and checkout on it:

    git branch pouet && git checkout pouet

  3. Apply the commit you want on this branch:

    git cherry-pick abcdefabcdef

    (abcdefabcdef is the sha1 of the commit you want to apply)

jag
As an aside, your second step can also be done in one command as `git checkout -b pouet`.
Greg Hewgill