How do you use a VCS (preferably git) to synchronize local directories?

0

I'd like to have a simple, script-like backup solution to synchronize 2 local directories which provides a "fail-safe"-mechanism allowing to undo 1 commited unwanted modification of a file that got synchronized.


Let's say I have 2 local directories d1 and d2 initially containing the exact same files.

Is it possible to use a version control system to synchronize any changes from d1 to d2 like this:

1. a file f1 in d1 gets modified

2. d1 is synchronized to d2

3. f1 in d1 gets modified again

4. d1 is synchronized to d2 again

5. the initial version of f1 gets deleted in both directories, so that only the current and the second latest version of the file remain in both directories/repositories (an undo is possible and disk space is saved)


Also, this is on Linux (Arch).

Thank you in advance for your expertise!

MCH

Posted 2012-08-20T02:21:33.163

Reputation: 73

First of all, this really does belong on Superuser, there is nothing programming related in this at all. Secondly, I would suggest RSYNC for keeping directories synced. – None – 2012-08-20T02:24:46.917

RSYNC doesn't provide undo, does it? – None – 2012-08-20T02:28:05.720

Not sure if this will fit your requirements, but it is a good read anyway: http://www.mikerubel.org/computers/rsync_snapshots/

– None – 2012-08-20T02:48:18.030

Thank you for that link! Seems like an excellent read indeed! I'm currently diving in :) – None – 2012-08-20T02:57:01.773

This is on SuperUser because this is a question about using software, not building it. Git is a developer's tool, but it is not being used for development (Or, not in any way that makes that important) here. SU is the place for this question. There's plenty of knowledge on SU, however--it's not like the two communities are segregated, either. I'm not sure you want git here, anyway. rsync and copying changed files to either a third location or just a .bak or something would fit your specifications. If you need them to be always identical forever, though... why not just use a symbolic link? – Phoshi – 2012-08-20T23:43:27.400

Well, while I appreciate the hint for a possible solution to my problem the user sosborn gave me (I'm still evaluating it), I did explicitly mention in my question, that I'd like to have a "simple, script-like backup solution" -- I think this involves building software in terms of creating a script. It is true however, that I didn't require git as a solution to this problem -- I also made that clear -- the title of the question is "How do you use a VCS (preferably git) to synchronize local directories?" By the way, I'm a software engineer. – MCH – 2012-08-21T00:01:57.293

Scripting is more within scope here, yes. We're talking about file copying and comparing modification times, not profiling functions or deciding design patterns. SU is the place for this question, and that absolutely doesn't mean you'll get worse answers. You're a software engineer, but you wouldn't use that as an excuse to not post on cooking.SE about making a meal, would you? – Phoshi – 2012-08-21T14:32:18.320

Just by comparing the amount of questions belonging to my tags, it is obvious, there are more people on stackoverflow.com which can answer this question. Would you rather eat Fugu made by a real cook or a housewife? Who of this 2 persons would know more about making it? – MCH – 2012-08-21T17:04:20.163

That's because those are tags for development tools. I could write a novel in Visual Studio and track progress with git, but that does not mean my question is about development. Your question is not about development, even if you are using a developer's tool to achieve it. A question being moved is not a bad thing, you are being placed somewhere better suited for your question, and thus more likely to receive an answer. If you seriously think there is a problem here, that's what meta.* is for. – Phoshi – 2012-08-21T17:15:53.840

Hmm maybe I should put it this way: If you have a question about cars, and there is a group of 10 engineers and a group of 50 engineers a mile apart, where do you go? – MCH – 2012-08-21T17:21:07.530

If I'm looking to replace a part, I go to the group most suited for that. Quantity does not equate to quality. Take your issue to meta if you want, but they'll tell you the same thing--your question is not about software development, it has no place in a software development Q&A site. – Phoshi – 2012-08-21T17:57:02.783

Answers

0

Just set up git in your directory and remember to commit any relevant changes. You can recover earlier versions from there. To assuage lurking paraoia, set up a repository elsewhere (another machine!) to push your updates there.

vonbrand

Posted 2012-08-20T02:21:33.163

Reputation: 2 083