![]() ![]() Go to Tools > Terminal to open a terminal tab. I’ll copy the SHA I want to revert to.įor the git rollback command, you need the RStudio Terminal, not the R Console. You can see all your project commits here with their commit messages (Hopefully you see why having descriptive commit messages is useful here!). ![]() Go back to the Git tab and click the Diff button and then History. How can you get back to an earlier version of a file you committed?įirst you need the git ID of that commit, called an S.H.A, or SHA. Obviously this would be easy to correct without git, but changes you’d like to roll back can of course be a lot more complex – and involve more than one file. You can now close the Commit window I’m going to make a change to the file that I won’t like, one that I’m going to want to undo. Type in a commit message – a note explaining a little about this commit. To actually commit the file, click the Commit button. That “stages” the file, which roughly means you’ve marked it as ready to be committed. First, select one or more files by checking the box next to their names. To commit a file with git in RStudio, go to the git tab in the top right pane. So why would you do this? One reason: Because git lets you revert back to a previous version of the file! No need to save multiple versions of a file: scriptworking.R, scriptfinal.R, scriptreallyfinal…. Any future commits save the changes made since your previous commit. To use git version control on this file, I need to “commit” that file. Next, I’ll create a new project in RStudio, and I’ll make sure to check “create a git repository.” I’ll add a little test R code. On Windows, look for the git.exe file somewhere like C:/Program Files/git/bin. On a Mac, it’s likely to be at usr/bin/git or usr/local/bin/git. And then make sure to tell RStudio where your “git executable” is. First you need to tell RStudio you want to use git. Those need to be run in a terminal window, not the RStudio R console. If you forget to do that, RStudio will prompt you with the git commands you need. Check out chapters 4, 6, and 7 for setup, including telling git your name and email address, which is important. If you have trouble with these set-up steps, I highly recommend checking out “Happy Git and GitHub for the useR” at by Jenny Bryan and Jim Hester. If you want to sync your local project with a GitHub repository, you’ll also need to set up a free GitHub account at github dot com slash join. Or, google “install git.” You need this if you want git version control on your local system. You can find git at git dash s.c.m dot com slash downloads. There are a couple of non-R initial system set-up tasks that I won’t be doing. But thanks to RStudio and the usethis package, git with R has become easier. When a viewer suggested I cover git version control, my first reaction was: I don’t have an hour. I’m Sharon Machlis at IDG Communications, here with episode 33 of Do More With R: Use Git and GitHub with Your R Projects. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |