<- ggplot(iris, aes(x = Sepal.Length, y = Sepal,Width, color = Species)) +
plot geom_point(size = 2) +
geom_smooth() +
xlab("Sepal Length (mm)") +
ylab("Sepal Width (mm)")
scale_color_manual(values = c("tan", "wheat", "burlywood2")) +
theme_bw()
Break it
1 Explore commit history
You might not find yourself needing to look back through your commit history often, but it is useful to have some familiarity. For example, I recently used it to recover a chunk of code to make a figure I deleted a month ago and decided I actually wanted.
Navigate to the workshop website’s GitHub repo. Using GitHub’s commit history feature, find the commit message “Reworked to add auto merge and conflict examples” and find the answers to the following questions.
- What is the commit ID?
- How many files did I edit?
- What change did I make to line 55 in the older version?
2 Break everything (and fix it)
2.1 Break your code
Using the IntroToGit_Activity
repository you forked in the collaboration activity, edit the script.R
file by replacing the code to create the plot with the code below.
Try running the new code. Does it work? Take a second to try to identify the source(s) of the error without using the diff.
View the diff for the
script.R
file. Can you tell where the changes to the code occurred?
- Fix the code by reverting the change using the RStudio GUI and check to see if the code runs as expected.
- (More advanced) - How would you recover the previous version if you committed the change but haven’t pushed it to GitHub yet?
Edit the code, save the file, and commit the changes but don’t push.
Use the terminal to perform a “soft” reset of your last commit
2.2 Break your repo
Create a more realistic repo:
- Create a new document in the forked repository (or another repository that isn’t important to you).
- Add this file to
.gitignore
so that it won’t be pushed to GitHub. Imagine that this is a large data set. - Sync your local repo with GitHub with usual the pull->stage->commit->push workflow.
Now assume that you are experiencing an error that cannot be resolved with one of the other methods. Reset your repository by following the xkcd steps.
- Copy the forked repository to another location on your computer
- Delete the original folder
- Clone the repository again from GitHub
- Check to see if any documents (e.g. the one you created early are missing)
- Move any missing documents into your new repo.
- Make sure you can pull and push changes.