~jan0sch/darcs-book
Showing details for patch ae2873a6dc041841976d06361cfe50729ccd29db.
diff -rN -u old-darcs-book/en/04-happy-little-accidents.md new-darcs-book/en/04-happy-little-accidents.md --- old-darcs-book/en/04-happy-little-accidents.md 2024-11-24 04:48:48.828030338 +0000 +++ new-darcs-book/en/04-happy-little-accidents.md 2024-11-24 04:48:48.828030338 +0000 @@ -118,3 +118,56 @@ And just like that, we have undone our `revert`. Isn't it nice to have an extra safe guard just in case something goes wrong? + +Roll-over! Roll-over! Roll-back! `rollback`! +-------------------------------------------- + +Another nice property of `darcs` is that every change has an inverse. Oh boy, +math jargon again. Let me explain. A change describes something we haveā¦ well +changed *duh*. Let's say we have added a line "happy happy joy joy" to a file. +The inverse of that change would be removing that line. So when you apply the +inverse of a change, it takes back all the modifications of that that change. +You can once again think of it in terms of numbers. When you have `x + 3` you +are adding `3` to some number `x`. You can get back to `x` by applying the +inverse of `3` which is `-3`. It's the same idea, just with changes. + +``` +$ echo "happy happy joy joy" >> story.txt +$ darcs record -m 'add some joy' +$ darcs log -v -p joy +patch 5ac28c7924511e5fffaf1f028b89158c429938a8 +Author: raichoo@example.com +Date: Wed Jun 27 16:31:28 CEST 2018 + * add some joy + hunk ./story.txt 2 + +happy happy joy joy +``` + +So, a couple of weeks later we figure that maybe this is just way too much joy +and we decide to roll back the change. We do that by using `darcs rollback` +which takes some changes and applies their inverse to the working tree. Just +like `log` `rollback` can take a `-p` flag to specify a pattern for selecting +matching patches. I know that the package name contains the word "joy" so I'm +using that. + +``` +$ darcs rollback -p joy +patch 5ac28c7924511e5fffaf1f028b89158c429938a8 +Author: raichoo@example.com +Date: Wed Jun 27 16:31:28 CEST 2018 + * add some joy +Shall I rollback this patch? (1/1) [ynW...], or ? for more options: y +Do you want to Rollback these patches? [Yglqk...], or ? for more options: y +hunk ./story.txt 2 ++happy happy joy joy +Shall I rollback this change? (1/1) [ynW...], or ? for more options: y +Do you want to Rollback these changes? [Yglqk...], or ? for more options: y +Changes rolled back in working directory +$ darcs whatsnew +hunk ./story.txt 2 +-happy happy joy joy +``` + +`rollback` does not create any new patches, it just applies the inverses of the +changes you have selected to your working tree, it's up to you to record a new +patch from them.