UW R-Ladies
4/14/23
A system to keep track of changes you make to a file, and revert to a previous version if something goes wrong
Changes are recorded and documented in a “commit”
The record of commits is version control!
one of the most common version control software programs, and is free and open source!
git becomes even more useful when you connect your local git repos to a remote git service such as GitHub
takes up a lot of room (there are size limits on GitHub)
you typically aren’t changing raw data (hopefully!), so it’s not really useful
you can still store data in a repo, but put it in a folder that included in the “.gitignore”
Note: All of these steps are very well explained on Jenny Bryan’s amazing website, happygitwithr.com
There are two formats git and git servers can use to communicate with each other, HTTPS or SSH. Each require two elements for authentication:
You can store these access credentials in your local git .config file, but you need to decide on SSH or HTTPS first. We’ll use HTTPS because it’s easier to set up (you can easily switch to SSH later!).
PATs are the style of authentication key that HTTPs uses
usethis::create_github_token()
function in R to generate a PAT -this will take you to the GitHub PAT websiteWe need to store the PAT in your local config file, and you won’t be able to see it again once you leave this page!
gitcreds
R package to store this PAT in your config filegitcreds::gitcreds_set()
in the R console? Enter password or token:
will appear. Copy the PAT from the GitHub page, and paste it into the R console and press enter.(Note: We normally would begin by pulling from the remote, but that wouldn’t do anything here because we just cloned the repo)
Fill in the panel that pops up to make a commit
This checks if there uncommitted changes. If the terminal says anything other than nothing to commit, working tree clean,
commit your changes.
13. Then, look at the most recent commits in this repo:
You can also do this via the R Studio git client… Click the “diff” button in the “Git” panel, and then the “History” button in the upper left corner. Click on a commit to see the changed files below.
Whichever method you chose, copy the “SHA” of the commit you want to revert to
In the Terminal window, use the git revert command to take your repository back to the commit you’ve chosen
“<<<” and “>>>”: make the beginning and end of the merge conflict
“===”: divides the two conflicting versions
Once you’ve found the commit with the version of the file you want, copy the code from that page (everything, or just what you want to change) and paste it into that file in R Studio.
Then, make a commit with an informative message!
This isn’t necessarily the most by the book way of doing things, but sometimes it’s a lot easier than doing a git revert!
Don’t be afraid to mess up! Just like with R, there are a ton of online resources about git and GitHub, and I’ve always been able to solve problems I’ve run into by Googling an error message!