Skip to content

Commit

Permalink
prompts: burn it all down, resets, gh search
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jun 27, 2016
1 parent 9dc8ea9 commit b8b0a3b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 43_prompt-burn-it-all-down.Rmd
Original file line number Diff line number Diff line change
@@ -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:

* <https://xkcd.com/1597/>
* <http://explainxkcd.com/wiki/index.php/1597:_Git>

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.

37 changes: 37 additions & 0 deletions 44_prompt-practice-resets.Rmd
Original file line number Diff line number Diff line change
@@ -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:

<https://git-scm.com/blog>
38 changes: 38 additions & 0 deletions 45_prompt-search-github.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Search GitHub {#search}

## Basic resources

GitHub searching

* <https://github.com/search/advanced>
* <https://help.github.com/articles/searching-code/>
* <https://help.github.com/articles/search-syntax/>

Read-only mirror of R source by Winston Chang:

* <https://github.com/wch/r-source>

Read-only mirror of all packages on CRAN by Gábor Csárdi:

* <https://github.com/cran>
* <http://cran.github.io>

## 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:

<https://github.com/search?utf8=✓&q=man-roxygen+in%3Apath&type=Code&ref=searchresults>
3 changes: 3 additions & 0 deletions _bookdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down

0 comments on commit b8b0a3b

Please sign in to comment.