dropbox-style svn/git/mercurial?: auto-commit upon

2020-04-04 04:08发布

问题:

I'm not a professional programmer, but I do some small solo projects and I would like some versioning and syncing, but going through the process of remember to commit and checkout (on different computers) is more of a hassle than, say, keeping code in a dropbox folder that automatically uploads to the cloud upon file change. Using the current copy is completely transparent to me, but there is no versioning. (Syncing is also a pain because I often don't open my laptop for days after getting home.)

Is there a way to have a codebase automatically commit upon file change (or just every few minutes) and automatically download the latest version if I want to continue my work from another computer?

Thanks!

回答1:

It depends on what your "projects" are.

Flashbake was created after science-fiction writer Cory Doctorow wanted to automatically capture and version his writing process at regular intervals:

Every 15 minutes, Flashbake looks at any files that you ask it to check (I have it looking at all my fiction-in-progress, my todo list, my file of useful bits of information, and the completed electronic versions of my recent books), and records any changes made since the last check, annotating them with the current timezone on the system-clock, the weather in that timezone as fetched from Google, and the last three headlines with your by-line under them in your blog's RSS feed (I've been characterizing this as "Where am I, what's it like there, and what am I thinking about?"). It also records your computer's uptime. For a future version, I think it'd be fun to have the most recent three songs played by your music player. (source)

It is based on git for versioning, and cron for automatic updates (git is sufficiently space-efficient to make this tractable). You may want to look at another review. The code is here.

If you really, really want file modification detection rather than a commit every X minutes (aka. paranoid about data), you may want something based on inotify (details - note those automated commits may add up quickly !).

Yet another option (that doesn't necessarily solve the auto-commit question, so you may want to mix) is to look at running git over dropbox. This has already been discussed here on SO.



回答2:

Dropbox keeps few versions of files in history. Hardly can be called "versioning", but you can restore files to some time back in the past.

If you really can not be bothered with commiting and merging, I'd say just live with dropbox, as it is nice and automatic.

You can set up Scheduled Task (if on Windows) or Cron Job (if Linux) that will make a commit/push every 5 minutes. And pull/update every time you start your computer. But I can see a potential nightmare waiting to happen, especially on pull/update, when manual merge is required.

Also, I'd advise using Mercurial, as it is much easier to learn/deal with than git, and more advanced than svn. This will take away some pain from version-control system.



回答3:

So what I ended up doing was using cloud sync for synology, (but I was using btsync in the past) to sync my code bases between several computers. This creates the immediate 'auto-sync' feature I was looking for and it's completely transparent to me. (This also takes care of the problems with having bloated auto-commits as mentioned above) This way you get versioning and auto-sync (or be forced to commit daily, or worry about having to commit when you need to leave your computer, or have to deal with any commit errors that come up before you close your laptop, or most of all have to rely one's fallible memory to remember to commit daily (big one for me!)). One SHOULD NOT be using git to sync (git is meant to version points in time, not sync). Note: just watch how you sync your .git folder so you dont break your work on one machine from the other via sync. If you blacklist .git, you can still clone the repo and push from either machine (but still not break things by syncing .git from one to the other).