From b8b0a3b8863de5274dab12e91d1950a60f570ac8 Mon Sep 17 00:00:00 2001 From: jennybc Date: Mon, 27 Jun 2016 01:50:12 -0700 Subject: [PATCH] prompts: burn it all down, resets, gh search --- 43_prompt-burn-it-all-down.Rmd | 24 +++++++++++++++++++++ 44_prompt-practice-resets.Rmd | 37 +++++++++++++++++++++++++++++++++ 45_prompt-search-github.Rmd | 38 ++++++++++++++++++++++++++++++++++ _bookdown.yml | 3 +++ 4 files changed, 102 insertions(+) create mode 100644 43_prompt-burn-it-all-down.Rmd create mode 100644 44_prompt-practice-resets.Rmd create mode 100644 45_prompt-search-github.Rmd diff --git a/43_prompt-burn-it-all-down.Rmd b/43_prompt-burn-it-all-down.Rmd new file mode 100644 index 00000000..32ff7d9a --- /dev/null +++ b/43_prompt-burn-it-all-down.Rmd @@ -0,0 +1,24 @@ +# Burn it all down {#burn} + +This is a highly inelegant, but effective technique for disaster recovery. + +It has been immortalized in an xkcd comic, so it must be ok: + + * + * + +Basic idea: + + * Commit early and often. + * Push to a remote, like GitHub, often. + * The state of things on GitHub is your new "worst case scenario". + * If you really screw things up locally, copy all the files (or the ones that have changed) to a safe place. + - Usually your files are JUST FINE. But it is easy to goof up the Git infrastructure when you're new at this. And it can be hard to get that straightened out on your own. + * Rename the existing local repo as a temporary measure, i.e. before you do something radical, like delete it. + * Clone the repo from GitHub to your local machine. You are back to a happy state. + * Copy all relevant files back over from your safe space. The ones whose updated state you need to commit. + * Stage and commit. Push. + * Carry on with your life. + +Practice this before you need it, so you see how it works. + diff --git a/44_prompt-practice-resets.Rmd b/44_prompt-practice-resets.Rmd new file mode 100644 index 00000000..7ec96382 --- /dev/null +++ b/44_prompt-practice-resets.Rmd @@ -0,0 +1,37 @@ +# Resetting {#reset} + +Practice recovering from mistakes. + +Use a repository you've create earlier in tutorial for this. It only needs to be local, i.e. this does not involve GitHub. + +If it's not your most recent commit, seriously consider just letting that go. Just. Let. It. Go. + +So you want to undo the last commit? + +If "YES UNDO IT COMPLETELY": `git reset --hard HEAD^`. You will lose any changes that were not reflected in the commit-before-last! + +If "YES undo the commit, but leave the files in that state (but unstaged)": `git reset HEAD^`. Your files will stay the same but the commit will be undone and nothing will be staged. + +If "YES go right back to the moment before I commited": `git reset --soft HEAD^`. Your files will stay the same but the commit will be undone. Even your staged changes will be restored. + +**If you just want to fiddle the most recent commit or its message, you can amend it. You can do this from RStudio!** + + * Make the change you want and amend the commit. + * Do you only want to change the commit message? + - Make another small change. Surely you have a typo somewhere? Amend the commit, which gives you the chance to edit the message + +To amend from the command line, using an editor to create the message: + +``` bash +git commit --amend +``` + +To amend from the command line, providing the new message: + +``` bash +git commit --amend -m "New commit message" +``` + +Git Reset Demystified: + + diff --git a/45_prompt-search-github.Rmd b/45_prompt-search-github.Rmd new file mode 100644 index 00000000..3ce4e6fc --- /dev/null +++ b/45_prompt-search-github.Rmd @@ -0,0 +1,38 @@ +# Search GitHub {#search} + +## Basic resources + +GitHub searching + + * + * + * + +Read-only mirror of R source by Winston Chang: + + * + +Read-only mirror of all packages on CRAN by Gábor Csárdi: + + * + * + +## Use case + +What if a function in a package has no examples? Or is poorly exampled? Wouldn't it be nice to find functioning instances of it "in the wild"? + +[Via Twitter](https://twitter.com/noamross/status/563422536633839617), Noam Ross taught me a clever way to do such searches on GitHub. Put this into the GitHub search box to see people using the `llply()` function from `plyr`: + +``` bash +"llply" user:cran language:R +``` + +Or just [click here](https://github.com/search?l=r&q=%22llply%22+user%3Acran+language%3AR&ref=searchresults&type=Code&utf8=✓). + +Another example that recently came up on r-package-devel: + +How to see lots of examples of roxygen templates? + +This search finds >1400 examples of roxygen templates in the wild: + + diff --git a/_bookdown.yml b/_bookdown.yml index 796e3ce5..11d08306 100644 --- a/_bookdown.yml +++ b/_bookdown.yml @@ -31,6 +31,9 @@ rmd_files: [ "40_prompt-clone.Rmd", "41_prompt-fork.Rmd", "42_prompt-fork-pr-bingo.Rmd", + "43_prompt-burn-it-all-down.Rmd", + "44_prompt-practice-resets.Rmd", + "45_prompt-search-github.Rmd", "50_more-content.Rmd",