5 <title>Game of Trees (Got): Examples</title>
6 <meta name="description" content="Game of Trees (Got) Examples">
7 <meta name="viewport" content="width=device-width, initial-scale=1">
8 <link rel="stylesheet" type="text/css" href="openbsd.css">
9 <link rel="canonical" href="https://gameoftrees.org/examples.html">
13 <i>Game of Trees</i></a>
20 These examples are supplemental documentation to the man pages, which are
21 available both in the installed system and
22 <a href="https://gameoftrees.org/manual.html">online</a>.
28 <a href="#amend" >Amending the latest commit</a><br>
29 <a href="#ports" >Using got(1) with ports tree</a>
36 <h2 id="amend"><a class="permalink" href="#rollback">Amending the latest commit</a></h2>
39 Sometimes a mistake is found in the latest commit on a branch.
40 This section explains how such a mistake can be corrected with Got.
43 As a first step, Got can create another commit which undoes the changes
44 made by the latest commit. Assuming a branch called <tt>master</tt>,
45 the latest commit on this branch can be identified by the same
46 name (<tt>master</tt>).
47 In a clean work tree according to <tt>got status</tt>, run:
49 $ <b>got backout master</b>
50 $ <b>got commit -m 'oops, roll back previous'</b>
53 Using <tt>got backout</tt> a second time will now fetch the rolled-back
54 change into the work tree as a local change which can be amended:</p>
57 $ <b>got backout master</b>
59 $ <b>got commit -m 'fixed version of previous change'</b>
62 The history of the tree latest commits on the branch would
63 now look something like this:
67 -----------------------------------------------
68 commit bcb49d15e041ddffb59397d2fe851fdb1729b005 (master)
69 from: Flan Hacker <flan_hacker@openbsd.org>
70 date: Wed Aug 14 22:07:22 2038 UTC
72 fixed version of previous change
74 -----------------------------------------------
75 commit 82f6abb8b1a22fe62d2a8a8d0cdbb73c9d85fcda
76 from: Flan Hacker <flan_hacker@openbsd.org>
77 date: Wed Aug 14 21:37:07 2038 UTC
79 oops, roll back previous
81 -----------------------------------------------
82 commit 7ef28ff8dd61cbf38f88784ea8c11e373757985f
83 from: Flan Hacker <flan_hacker@openbsd.org>
84 date: Wed Aug 14 21:10:00 2038 UTC
86 this is surely a great idea!
91 If commit <tt>7ef28ff8dd61cbf38f88784ea8c11e373757985f</tt> has already
92 been copied to another repository, our story ends here because the history
93 must now be considered immutable.
96 Otherwise, the local branch history can be edited to cover up our little
97 mistake. First, find the ID of the parent commit of the bad commit:
100 $ <b>got log -l 4 | grep ^commit| tail -n 1</b>
101 commit e27a7222faaa171dcb086ea0b566dc7bebb74a0b (origin/master)
105 Back-date the work tree to this commit and ask Got to edit the history
106 leading up to the latest commit on the branch:
109 $ <b>got update -c e27a7222fa</b>
110 $ <b>got histedit</b>
114 The <tt>histedit</tt> command will open a histedit script in an editor:
117 # Available histedit commands:
118 # pick (p): use commit
119 # edit (e): use commit but stop for amending
120 # fold (f): combine with commit below
121 # drop (d): remove commit from history
122 # mesg (m): single-line log message for commit above (open editor if empty)
123 # Commits will be processed in order from top to bottom of this file.
124 pick 7ef28ff8dd61cbf38f88784ea8c11e373757985f this is surely a great idea!
125 pick 82f6abb8b1a22fe62d2a8a8d0cdbb73c9d85fcda oops, roll back previous
126 pick bcb49d15e041ddffb59397d2fe851fdb1729b005 fixed version of previous change
130 To make the mistaken commits disappear from history, the corresponding
131 lines can changed to execute <tt>drop</tt> commands, and the log message
132 of the latest commit can be changed to that of the original commit:
135 <b>drop</b> 7ef28ff8dd61cbf38f88784ea8c11e373757985f this is surely a great idea!
136 <b>drop</b> 82f6abb8b1a22fe62d2a8a8d0cdbb73c9d85fcda oops, roll back previous
137 pick bcb49d15e041ddffb59397d2fe851fdb1729b005 fixed version of previous change
138 <b>mesg this is surely a great idea!</b>
142 After saving the file and exiting the editor, Got will create a new
143 version of history which does not contain the mistake:
146 $ <b>got log -l 1</b>
147 -----------------------------------------------
148 commit 60b83404dd25547f19d9b468b931809541a3325c (master)
149 from: Flan Hacker <flan_hacker@openbsd.org>
150 date: Wed Aug 14 22:17:12 2038 UTC
152 this is surely a great idea!
156 <p id="callout">CAVEAT:
157 <p>The <tt>mesg</tt> command of the histedit script only accepts a
158 single-line log message argument. Omit the argument to write a new
159 multi-line log message in an editor:
163 pick bcb49d15e041ddffb59397d2fe851fdb1729b005 fixed version of previous change
167 <h2 id="ports"><a class="permalink" href="#ports">Using got(1) with ports tree</a></h2>
169 Clone the ports repository from github. This step currently requires git(1):
172 $ <b>mkdir /var/git</b>
174 $ <b>git clone --bare https://github.com/openbsd/ports.git</b>
176 <p>We jump into ports.git directory and we create our new branch to work with (let's say
180 $ <b>cd ports.git</b>
181 $ <b>got branch mystuff</b>
183 We check that the <tt>master</tt> and the new branch are in sync:
186 $ <b>got branch -l</b>
187 master: 05a7abcec81fc1865d1983314b6783680ab31f689
188 mystuff: 05a7abcec81fc1865d1983314b6783680ab31f689
190 <p>Now we need to checkout the content inside our new branch <tt>mystuff</tt>
194 $ <b>got checkout -b mystuff ports.git</b>
196 A /var/git/ports/x11/yeahconsole/distinfo
197 A /var/git/ports/x11/yeahconsole/patches/patch-Makefile
198 A /var/git/ports/x11/yeahconsole/pkg/DESCR
199 A /var/git/ports/x11/yeahconsole/pkg/PLIST
200 A /var/git/ports/x11/yeahlaunch/Makefile
201 A /var/git/ports/x11/yeahlaunch/distinfo
202 A /var/git/ports/x11/yeahlaunch/patches/patch-yeahlaunch_c
203 A /var/git/ports/x11/yeahlaunch/pkg/DESCR
204 A /var/git/ports/x11/yeahlaunch/pkg/PLIST
207 <p>As <code>got</code> says, now shut up and hack:
210 $ <b>cd /var/git/ports</b>
211 $ <b>cd www/nextcloud</b>
212 $ <b>vim pkg/README</b>
214 <p>So we changed the README file inside the Nextcloud port and we need to cook the diff:
218 diff 05a7abcec81fc1865d1983314b6783680ab31f689 /var/git/ports
219 blob - 47bfbdd7fa7aaf027971ac5c62db25dde75595d7
220 blob + 71d2df1463ae11c9b66403d401c16fff63382b2c
221 --- www/nextcloud/pkg/README
222 +++ www/nextcloud/pkg/README
223 @@ -96,12 +96,20 @@ server "domain.tld" {
224 block return 301 "$DOCUMENT_URI/index.php"
227 - location "/nextcloud/ocm-provider/" {
228 - block return 301 "$DOCUMENT_URI/index.php"
229 + location "/.well-known/carddav" {
230 + block return 301 "https://$SERVER_NAME/nextcloud/remote.php/dav"
233 - location "/nextcloud/ocs-provider/" {
234 - block return 301 "$DOCUMENT_URI/index.php"
235 + location "/.well-known/caldav" {
236 + block return 301 "https://$SERVER_NAME/nextcloud/remote.php/dav"
239 + location "/.well-known/webfinger" {
240 + block return 301 "https://$SERVER_NAME/nextcloud/public.php?service=webfinger"
243 + location match "/nextcloud/oc[ms]%-provider/*" {
244 + directory index index.php
247 ---8<---------------------------------------------------------------------------
249 <p>Time to commit those changes in our branch <tt>mystuff</tt>, so we can keep
253 $ <b>got commit -m "Add new examples for httpd(8) to shut up warnings"</b>
254 M www/nextcloud/pkg/README
255 Created commit 7848652ef6243db09841d449f346f21fc6386633
257 <p>Paranoid? Probably yes, let's check again our diff against <tt>master</tt>:
259 $ <b>got diff master mystuff</b>
260 diff refs/heads/master refs/heads/mystuff
261 blob - 47bfbdd7fa7aaf027971ac5c62db25dde75595d7
262 file + www/nextcloud/pkg/README
263 --- www/nextcloud/pkg/README
264 +++ www/nextcloud/pkg/README
265 @@ -96,12 +96,20 @@ server "domain.tld" {
266 block return 301 "$DOCUMENT_URI/index.php"
269 - location "/nextcloud/ocm-provider/" {
270 - block return 301 "$DOCUMENT_URI/index.php"
271 + location "/.well-known/carddav" {
272 + block return 301 "https://$SERVER_NAME/nextcloud/remote.php/dav"
275 - location "/nextcloud/ocs-provider/" {
276 - block return 301 "$DOCUMENT_URI/index.php"
277 + location "/.well-known/caldav" {
278 + block return 301 "https://$SERVER_NAME/nextcloud/remote.php/dav"
281 + location "/.well-known/webfinger" {
282 + block return 301 "https://$SERVER_NAME/nextcloud/public.php?service=webfinger"
285 + location match "/nextcloud/oc[ms]%-provider/*" {
286 + directory index index.php
289 ---8<---------------------------------------------------------------------------
291 <p>Now, let's send that diff to ports@ for some OKs.
294 <p>Once the diff has been committed to CVS the same change will eventually show
295 up on github as well. Fetch incoming changes to the <tt>master</tt> branch
299 $ <b>cd /var/git/ports.git</b>
300 $ <b>git fetch origin master:master</b>
303 <p>Next, rebase the <tt>mystuff</tt> branch onto the latest <tt>master</tt>:</p>
306 $ <b>cd /var/git/ports</b>
308 (status should be clean; revert or commit local changes if needed)
309 $ <b>got update -b master</b>
310 $ <b>got rebase mystuff</b>
314 Now we can shut up and hack again!