views:

252

answers:

4

Update: I think this is related to an issue with the windows git client msysgit. Sorry to trouble you guys. http://code.google.com/p/msysgit/issues/detail?id=379&colspec=ID%20Type%20Status%20Priority%20Component%20Owner%20Summary

I'm looking for a way to keep several client boxes in synch with a remote git repo. Forcing updates from the remote repo and abandoning anything that may have changed on the client boxes.

The problem I'm running into is that the client boxes will modify some of the files (installation logs etc.) and gives me a merge nightmare when I need to update them from the remote repo. I've tried several commands to try and reset their local changes (the local changes should just be abandoned), but none seem to be working as advertised (git reset --hard).

I don't want to do a clone and then delete the .git dir on these boxes as I'd prefer them to only update with changes rather than pulling down the entire repo every time.

Any ideas?

+1  A: 

It sounds like you are looking for rsync, not git. Can you explain a bit more why you would want to use a full revision control system to "merely" keep some files in sync?

Gerco Dries
Maybe I didn't explain it well. It's not that I want to synch only certain files, it's that I want the synch to be 1-way only. Master and slaves.
Dave Rapin
@Dave: Gerco's suggestion sounds like a good one - rsync can be used for 1-way syncing. However it will not, AFAIK, remove files which are newly created on the client but do not exist in the master copy. For this, git gives you 'git clean -fdx'.
Gareth Stockwell
@gareth: rsync has the `--delete` option to delete files that exist in the destination, but not the source. I think, unless he *needs* Git for some reason not specified, rsync would work just fine.
Dan Moulding
+1  A: 

The following two commands should reset the client's working tree to a clean state, i.e. identical to how it was following the preceding git clone:

git reset --hard HEAD

This will undo any modifications made to files which are tracked (i.e. which exist in the repo).

git clean -fdx

This will remove any files which have been newly created by the client, i.e. which are not tracked by git.

Gareth Stockwell
unfortunately after running both these commands then a git status I'm still seeing several *modified* not yet committed files... My client machines are windows boxes so maybe it's an issue with the msysgit client.
Dave Rapin
+1  A: 

I'm assuming you have a good reason for using Git for this, rather than rsync.

This is how I'd do it (on the Clients):

git fetch origin
git reset --hard origin/master
git clean -dfx

Note that you need to reset to origin/master rather than HEAD because the local HEAD doesn't include the origin's newest commits (yet).

Dan Moulding
Still no go. I think it must be a problem with the git client.
Dave Rapin
+1  A: 

It's strange, git reset --hard should remove any change made in the local repositories.

you can try git stash && git pull, it just move the changes in some kind of temporay branch (git stash clear to remove any trace of the changes)

if that does not work, you can try this (assuming you are on the master branch and that the tmp branch does not exists)

git checkout origin/master -b tmp
git branch -D master
git branch -m master
mathroc
I've tried the stash already and no worky. I know it sounds wierd, but I've been using git for a while now and have only just run into this issue now. Branching it sounds like it should work, I'll give that a whirl.
Dave Rapin