forked from crawl/crawl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.txt
473 lines (343 loc) · 15.5 KB
/
quickstart.txt
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
This is for those who haven't used git before and need a crash-course on basic
operations. I'll keep this as simple as possible, and focus specifically on
working on Stone Soup, rather than git in general. I've also added links to
the official git docs at the end, which you can read instead of, or in addition
to this, if you're inclined.
Installing git
--------------
I strongly recommend using at least git 1.6 or later. While you can use older
versions, the newer versions are much more user-friendly. This guide assumes
you're using 1.6.
Linux: Install git using your package manager. The git package is usually
called git-core.
Mac: Install git using Mac ports or Fink. The MacPorts port is called git-core
(sudo port install git-core).
Windows: Install MSYS2 (git-for-windows.github.io/#contribute). See the detailed
instructions in INSTALL.txt for further setup information. Be sure to download
the 'Git for Windows SDK', as this also includes all of the necessary tools
to build Crawl - other installers include only Git itself.
Using git for Stone Soup development
------------------------------------
0. Basic git settings:
Set your name for git to use when committing changes:
$ git config --global user.name "John Doe"
Set your email address:
$ git config --global user.email "[email protected]"
This sets your default e-mail id for all git work on your system. You can
use any e-mail address you have. In the above, John Doe is still using his
old sourceforge id as a spam-catching measure.
1. Clone the crawl repository from github (analogous to svn checkout):
Developers (anyone with commit rights to the git repo):
$ git clone [email protected]:crawl/crawl.git
Other users:
$ git clone https://github.com/crawl/crawl.git
"git clone" clones Crawl's entire git repository to your machine. When it's
done, you have a full local copy of the crawl repository with all its
history.
If you want to build the contributing libraries rather than using the
versions already installed on your system, you can fetch the submodules:
$ cd crawl
$ git submodule update --init
2. Sanity-check your cloned repository (optional):
When you come back to a git repository after a while, you may not recall
where you cloned it from. You can check with:
$ git remote -v
This reports:
origin [email protected]:crawl/crawl.git (fetch)
origin [email protected]:crawl/crawl.git (push)
See all available branches in the repository:
$ git branch -a
See all tags:
$ git tag
3. SSH keys (for core developers):
If you want to push to the Github repository, you will need to create an ssh
key and upload your public key to github.com.
Let's create an ssh key (if you already have a key, skip this step):
$ ssh-keygen
You can accept all the default options and use an empty passphrase for
convenience (don't do this on an account you share with other people, or
they can commit to the repository too :P)
Once the key is generated, you'll have two files id_rsa, and id_rsa.pub in
your ~/.ssh (the .ssh directory in your home directory). id_rsa is your
private key, and should not be shared or given to anyone else (or they can
pretend to be you); id_rsa.pub is your public key, and this is what you'll
upload to github.
Go to github.com, login, and from the menu bar, hit the setting gear icon at
the top-right to access your account settings. Click on "SSH keys" and then
on "Add SSH key".
Enter your account name or another descriptive name as the title. Copy the
one line in your id_rsa.pub, and paste it into the Key text area. Hit Save
when you're done.
Within a few minutes of uploading your key, you should be able to push/pull
from github.com.
Windows users (msysgit) can follow these exact same steps in a git bash
prompt.
4. Updating your repository with the latest changes from github.com:
Use
$ git pull
to grab the latest commits from github.com.
git pull assumes your working tree is clean; it will refuse to overwrite any
files that you've modified locally (unlike svn's "svn update", which will
happily try to modify the file anyway, and add conflict markers if there are
conflicts).
If git pull fails because you have local changes, you have two options:
1. Complete your local changes and create a commit, then pull
again.
2. Temporarily save (stash) your local changes, pull changes from github,
and reapply your local changes:
$ git stash
(this saves your local changes)
$ git pull
(grab changes from github)
$ git stash apply
(reinstate your local changes)
If your local changes conflict with the changes from github, git stash
apply will warn you of the conflict and add conflict markers to the
relevant files.
5. Committing a change to the 'master' branch:
git's master branch is the equivalent of svn trunk. Immediately after
cloning a repository, the cloned crawl repo will be on the master
branch. You can check what branch you're working on at any time with:
$ git branch
The active branch will be asterisked.
Before starting work, let's make sure our working copy is not dirty:
$ git status
# On branch master
nothing to commit (working directory clean)
Looking good. For our first change, let's assume we're fixing a bug in, say,
player.cc.
$ vim player.cc
<hackhackhack>
$ make
<test; that bugfix rocks the world>
Let's check how git sees things now:
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: player.cc
#
no changes added to commit (use "git add" and/or "git commit -a")
git sees that we've modified player.cc. You can see what changes you've made
with:
$ git diff
Time to actually commit the change:
$ git commit -a
git will bring up your preferred editor for you to enter your commit
message. On Windows, you may have to set your EDITOR environment variable;
alternatively, you can specify your commit message on the command line:
$ git commit -a -m "Fitted player.cc with mountain dwarves"
When you're done, your change has been committed to your local
repository. Let's try git status again:
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
So git's telling us that we have one local commit that we haven't sent to
github's git repository yet. Let's send in our fix to github.com (core devs
only):
$ git push
You will be prompted for your password again. git should then push your
commit, producing a last line that looks like:
54ea5f1..ec2e15e master -> master
The exact commit ids will differ, but a successful push looks like
this. Your push may fail if someone has pushed changes to github already
(git will warn you about a non-fast-forward). In this case, just pull and
push again:
$ git pull
$ git push
6. Patching (for regular contributors, not core devs):
Once you have committed and tested a change, you can create a patch for it.
You can then send this patch to the devs or upload it to a mantis issue for
review and potential addition to the game.
To start, make and save your changes in whatever text editor you choose.
Then, as explained above, commit those changes:
$ git commit -a
In most cases, this is a good time to compile and test the change. Make sure
it works correctly, testing in Wizard Mode as appropriate.
When you're happy with your patch, you can make a patch file with the
format-patch command. For example:
$ git format-patch -1
This will create a patch from the most recent commit you've made. The patch
file will be placed in your base Crawl source directory.
For a more detailed patch creation guide, check out patch_guide.txt in the
/docs/develop/ directory.
7. Viewing revision history:
You can see a history of changes with
$ git log
git log by itself may make it appear that the change history is a straight
line, but we know that git can handle branching histories. We can request
that git log show us the branching history with:
$ git log --graph
You can also view history using the gitk GUI (this is installed by default;
everyone should have it, and I recommend it):
$ gitk
The history commands normally show you the history of the current branch,
but you can view other branches/tags' histories by naming the branch or tag:
$ gitk origin/stone_soup-0.16
If you want to annotate a file with last author and commit to change each
line in the file, you can use git blame, which is similar to svn blame:
$ git blame player.cc
8. Committing a change to a different branch:
So far we've restricted our attention to 'master', which is the easiest
branch to work with, since it's selected by default. Now let's say we have a
bug report with a 0.16 save, and we need the 0.16 code to test the save
with:
Let's take a look at the branches we have locally:
$ git branch
* master
The only local branch in our repository is master. Let's look at
the branches in the remote repository (github):
$ git branch -r
origin/HEAD -> origin/master
origin/master
origin/stone_soup
...
origin/stone_soup-0.16
So our local repository has a "master" branch corresponding to github's
"master" branch. We do not yet have a branch corresponding to github's
"stone_soup-0.16", so let's create the branch and switch to it. By default
git will find find the branch origin/stone_soup-0.16 and create a local
branch that tracks this one:
$ git checkout stone_soup-0.16
Branch stone_soup-0.16 set up to track remote branch stone_soup-0.16
from origin.
Switched to a new branch 'stone_soup-0.16'
master and stone_soup-0.16 are both local branches now:
$ git branch
master
* stone_soup-0.16
git status will also confirm that we're on 0.16 now:
$ git status
# On branch stone_soup-0.16
nothing to commit (working directory clean)
A quick peek at the history to make really sure we're on 0.16:
$ git log
To grab the latest changes for 0.16:
$ git pull
Ok, now we compile 0.16, test the 0.16 save and verify that a bug
exists. Once we've fixed the bug, we create a commit:
$ git commit -a
Check git status:
$ git status
# On branch stone_soup-0.16
# Your branch is ahead of 'origin/stone_soup-0.16' by 1 commit.
#
nothing to commit (working directory clean)
Right, we're ready to push our fix to github.
$ git push --dry-run -v
Pushing to [email protected]:crawl/crawl.git
To [email protected]:crawl/crawl.git
b05bb66..976e722 stone_soup-0.16 -> stone_soup-0.16
So git wants to push the local stone_soup-0.16 branches to the corresponding
branches on github. Run the same command without --dry-run to actually push
the commit.
Once you're done working on 0.16, you can switch back to "master"
with:
$ git checkout master
The next time you need to work on 0.16 again, you can return to it
with:
$ git checkout stone_soup-0.16
9. Common operations:
Reverting Changes
-----------------
It often happens that you make a change to a file that you didn't
want, or accidentally delete files that you did want. You can
revert a file to its pristine version as:
$ git checkout player.cc
This also works to bring back files you accidentally deleted. If
you forget these commands, "git status" will remind you:
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: mt19937ar.cc
#
no changes added to commit (use "git add" and/or "git commit -a")
Adding New Files
----------------
When committing changes with "git commit -a", newly created files
won't be added to the commit unless you request it with "git add".
Let's take an example:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dwim.cc
nothing added to commit but untracked files present (use "git add" to track)
Before we commit, we must add the new file:
$ git add dwim.cc
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: dwim.cc
$ git commit -a
In general, "git status" is your friend. It will usually tell you
exactly what you need to do.
10. Branching:
Let's say we want to create a branch with some tentative or incomplete
changes that we want others to look at or change. Here's how you'd do it,
using a branch called pizza_tornado as an example:
a) Branch pizza_tornado from master:
$ git checkout -b pizza_tornado master
Let's check our local branches now:
master
stone_soup-0.16
* pizza_tornado
pizza_tornado is currently a *local* branch. github's git repo doesn't
have it yet.
b) Push the local branch to github with a --dry-run first to make sure we're
not lousing up anything:
$ git push --dry-run -v origin pizza_tornado
Pushing to [email protected]:crawl/crawl.git
To [email protected]:crawl/crawl.git
* [new branch] pizza_tornado -> pizza_tornado
Now for the real push:
$ git push origin pizza_tornado
c) Point your local branch at the new branch in github:
Now that we've created the branch on github, we want to set up our local
"pizza_tornado" to get changes from github's "pizza_tornado" when we do a
git pull. We do this as:
Tell git that pizza_tornado's remote repository is on github:
$ git config branch.pizza_tornado.remote origin
And that the corresponding branch in github is pizza_tornado:
$ git config branch.pizza_tornado.merge refs/heads/pizza_tornado
Now you can pull changes from github's pizza_tornado branch:
$ git pull
This is only necessary for new branches that you create locally and push
to github. This configuration is automatically set up for you when you
work with branches that already exist on github.
11. Committing changes from one major branch of development to another:
Once we create a stable branch (say 0.16), we usually make all changes to
trunk, but apply bugfixes to the 0.16 branch as well. You can apply changes
from master to stone_soup-0.16 with git cherry-pick:
$ git checkout master
[ make the changes for the bugfix ]
$ git commit -a
$ git checkout stone_soup-0.16
And cherry-pick the tip commit of the master branch (the bugfix we just
committed there):
$ git cherry-pick -x master
If the commit you want to cherry-pick is not the tip of a branch, just use
the commit's id:
$ git cherry-pick -x b0ed1449
git push will then send in the commits from both branches.
Additional Reading:
------------------
I've intentionally kept my examples very simple and glossed over a lot of
details. I've covered the common operations in the svn workflow, but git can do
much more for you if you spend a little time learning it.
git documentation central:
http://git-scm.com/documentation
git tutorial:
http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
Another crash course for svn users:
http://git-scm.org/course/svn.html