Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, so I actually came up with a better solution to this problem. <a href="https://stackoverflow.com/questions/9556807/track-files-locally-but-never-allow-them-to-be-pushed-to-the-remote-repository/9566508#9566508">My previous solution</a>, which involved a second git repository, quickly became problematic due to the size of the sqlite files I was working with; git <strong>cannot</strong> handle large files. I investigated various ways to improve git's ability to handle the files (e.g. <a href="http://caca.zoy.org/wiki/git-bigfiles" rel="nofollow noreferrer">git-bigfiles</a>, <a href="http://git-annex.branchable.com/" rel="nofollow noreferrer">git-annex</a>) but nothing seemed to handle my situation elegantly.</p> <p>The answer: <strong>symlinks.</strong></p> <p>N.B. This solution is pretty Unix specific, but you will probably be able to rework it for non-Unix systems.</p> <h3>Problem #1: Ensure that the data is <strong>never</strong> sent to the remote repository.</h3> <p>This one was easy. Similar to my previous solution, I store the data outside of the repository.</p> <pre><code>Root-Directory/ My-Project/ .git/ Source-Code-and-Stuff/ My-Project-Data/ A-Big-Sqlite-File.sqlite </code></pre> <p>Because the data files aren't in the repository, there's no need to worry about them being indexed by git.</p> <h3>Problem #2: Different branches should reference different versions of the data.</h3> <p>This is where symlinks come into play. A symlink is effectively a shortcut to a file, so the idea is to put a symlink to the data file inside the repository. Symlinks are indexed by git (and they're very small), so different branches can have different symlinks.</p> <p>To explain this, let's take an example project, which has a currently live version (1.1) on the <strong>master</strong> branch; and a new version (1.2) on the <strong>version-1.2</strong> branch. For simplicity's sake, this project only has one data file: <em>Data.sqlite</em>.</p> <p>The data file is stored inside the <em>My-Project-Data</em> directory mentioned above, and versioned on the filesystem like so:</p> <pre><code>My-Project-Data/ v1.1/ Data.sqlite v1.2/ Data.sqlite </code></pre> <p>The data file is added to the repository by using a symlink:</p> <pre><code>My-Project/ .git/ Source-Code-and-Stuff/ Data-Symlink.sqlite </code></pre> <p>On the <strong>master</strong> branch, <em>Data-Symlink.sqlite</em> is</p> <pre><code>../../My-Project-Data/v1.1/Data.sqlite </code></pre> <p>and on the <strong>version-1.2</strong> branch it is</p> <pre><code>../../My-Project-Data/v1.2/Data.sqlite </code></pre> <p>So when development on version 1.3 begins, the following bash script will set everything up:</p> <pre><code># Get to the root directory cd path/to/Root-Directory # Enter the data directory cd My-Project-Data # Make a directory for the new version and enter it mkdir v1.3 cd v1.3 # Copy the new sqlite file into it cp ~/path/to/data/file.sqlite Data.sqlite # Move to the project directory cd ../../My-Project # Create a new branch git checkout -b version-1.3 # Move to the source code directory and delete the current symlink cd Source-Code-and-Stuff rm Data-Symlink.sqlite # Create a symlink to the new data file ln -s ../../Project-Data/v1.3/Data.sqlite Data-Symlink.sqlite # Commit the change cd ../ git add Source-Code-and-Stuff/Data-Symlink.sqlite git commit -m "Update the symlink" </code></pre> <h3>Conclusion</h3> <p>Obviously this isn't a perfect solution. If you're working with a team, everyone on the team will need to have the same relative directories - symlinks are relative paths, so the absolute path to <em>Root-Directory</em> can change, but <em>My-Project</em> and <em>My-Project-Data</em> <strong>must</strong> exist within it. But my personal opinion is that the benefits outweigh this minor caveat. In the actual project I'm using this technique with I have an 800MB sqlite file for the data, and being able to switch between live and development branches and have my project automatically update the data file is priceless.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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