1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
<!DOCTYPE html>
<html>
<head>
<title>
The Codex »
Git Is Not Magic
</title>
<link
rel='stylesheet'
type='text/css'
href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'>
<link
rel="stylesheet"
type="text/css"
href="../media/css/reset.css">
<link
rel="stylesheet"
type="text/css"
href="../media/css/grimoire.css">
</head>
<body>
<div id="shell">
<ol id="breadcrumbs">
<li class="crumb-0 not-last">
<a href="../">index</a>
</li>
<li class="crumb-1 not-last">
<a href="./">git</a>
</li>
<li class="crumb-2 last">
scratch
</li>
</ol>
<div id="article">
<h1 id="git-is-not-magic">Git Is Not Magic</h1>
<p>I'm bored. Let's make a git repository out of whole cloth.</p>
<p>Git repos are stored in .git:</p>
<pre><code>fakegit$ mkdir .git
</code></pre>
<p>They have a “symbolic ref” (which are text files, see <a href="http://jk.gs/git-symbolic-ref.html"><code>man
git-symbolic-ref</code></a>) named <code>HEAD</code>, pointing
to the currently checked-out branch. Let's use <code>master</code>. Branches are refs
under <code>refs/heads</code> (see <a href="http://jk.gs/git-branch.html"><code>man git-branch</code></a>):</p>
<pre><code>fakegit ((unknown))$ echo 'ref: refs/heads/master' > .git/HEAD
</code></pre>
<p>The have an object database and a refs database, both of which are simple
directories (see <a href="http://jk.gs/gitrepository-layout.html"><code>man
gitrepository-layout</code></a> and <a href="http://jk.gs/gitrevisions.html"><code>man
gitrevisions</code></a>). Let's also enable the reflog,
because it's a great safety net if you use history-editing tools in git:</p>
<pre><code>fakegit ((ref: re...))$ mkdir .git/refs .git/objects .git/logs
fakegit (master #)$
</code></pre>
<p>Now <code>__git_ps1</code>, at least, is convinced that we have a working git repository.
Does it work?</p>
<pre><code>fakegit (master #)$ echo 'Hello, world!' > hello.txt
fakegit (master #)$ git add hello.txt
fakegit (master #)$ git commit -m 'Initial commit'
[master (root-commit) 975307b] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
fakegit (master)$ git log
commit 975307ba0485bff92e295e3379a952aff013c688
Author: Owen Jacobson <owen.jacobson@grimoire.ca>
Date: Wed Feb 6 10:07:07 2013 -0500
Initial commit
</code></pre>
<p><a href="https://www.youtube.com/watch?v=3VwVpaWUu30">Eeyup</a>.</p>
<hr>
<p>Should you do this? <strong>Of course not.</strong> Anywhere you could run these commands,
you could instead run <code>git init</code> or <code>git clone</code>, which set up a number of
other structures, including <code>.git/config</code> and any unusual permissions options.
The key part here is that a directory's identity as “a git repository” is
entirely a function of its contents, not of having been blessed into being by
<code>git</code> itself.</p>
<p>You can infer a lot from this: for example, you can infer that it's “safe” to
move git repositories around using FS tools, or to back them up with the same
tools, for example. This is not as obvious to everyone as you might hope; people </p>
</div>
<div id="comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<div id="footer">
<p>
The Codex —
Powered by <a href="http://markdoc.org/">Markdoc</a>.
<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/git/scratch.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/git/scratch.md">history</a>).
</p>
</div>
</div>
</body>
</html>
|