Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo git repos for the same files
    text
    copied!<p>On my development computer I've previously used git simply as an automatic backup / recovery system. I know this isn't quite how git is intended to be used, but it has been very effective for me. I have a simple script that runs every 5 minutes (a la Windows Task Scheduler) and checks to see if any files have changed. If so, it creates a new commit (with the message "Automatic Commit") and pushes it to a mirror I have on an external hard drive. I can extend this to push to mirrors in other locations, too.</p> <p>I don't want to stop doing this, as the system has saved my life more than once. Between power failures, accidental file deletions, or a client suddenly deciding they liked how the project looked 2 months ago and they want to revert all the changes - the ability to roll everything back to any point in time has been invaluable.</p> <p>Now the problem comes when I want to put one of these repositories on github for collaborative work. Every time I push to github it creates tens or hundreds or commits, often with incomplete code since I was in the middle of modifying a file when five minutes rolled around.</p> <p>I would like to have a second repository of sorts residing in the same directory and watching over the same files, however I want it to only commit manually. This way when I push to github there are only meaningful commits and all my automatic backups are hidden from prying eyes.</p> <p>Is this even possible?</p> <p>Quick Edit -</p> <p>Googling around, could the <code>git rebase</code> command be of any use? It seems like it may destroy all the automatic commits, which isn't exactly the ideal behavior.</p> <p>Long Edit -</p> <p>This little project has been a <strong>NIGHTMARE</strong>.</p> <p>Following the advice from @janos I set set up a second repository in every folder. To set these up I simply used <code>git clone</code> on the current repository. I modified my <code>autosave.bat</code> file to utilize <code>GIT_DIR</code> and <code>GIT_WORK_TREE</code> and thought everything would be dandy... it wasn't</p> <p>First, try the following on a Windows 7 PC for fun:</p> <pre><code>test.bat -------- CD C:\SomeFolder FOR /D %%i in (*) DO ( CD %%i set GIT_WORK_TREE=%cd% echo %GIT_WORK_TREE% CD .. ) </code></pre> <p>The results of this should be obvious, right? We step through every sub-directory in <code>SomeFolder</code>, set it to the current <code>GIT_WORK_TREE</code>, then output <code>GIT_WORK_TREE</code>. The output:</p> <pre><code>C:\SomeFolder C:\SomeFolder C:\SomeFolder C:\SomeFolder .... </code></pre> <p>It looks like batch scripts are executed out-of-order (<code>set GIT_WORK_TREE=%cd%</code> is processed before <code>CD %%i</code> has completed). You can only imagine the horror this wreaked on my backups when every single project was in every other project's repository.</p> <p>I tried to get around this using <code>git --git-dir=backup.git --work-tree=%cd%</code> only to get errors when folders had a space in the name (I had to put <code>%cd%</code> in quotes)</p> <p>I finally got that working and <code>backup.git</code> wasn't recognized as a git directory and was <strong>added to the repository!</strong> I added the following to my .gitignore to be safe:</p> <pre><code># git is really making me angry today /.git/ /backup.git/ </code></pre> <p>With that I think it's finally working, but I shudder to test my remote backups and see if they're actually set up correctly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload