I'm using git as a version control system in RStudio. I have several different versions of an R script saved in git. Lets say, I've deleted a block of code but I've now decided I want to re-insert the code into my current R script. I know the code includes the function ddply. This is my current workflow:

I open the Terminal in RStudio, and type:

git grep ddply $(git rev-list --all)

This brings up hundreds of lines of code, such as:

2c975e1faee880545546646648f5be2b55f60fc757c29828f1f:reports/:data <- ddply(x, .(as.factor(y), summarise, mean(count))
2c975e1faee880545546646648f5be2b55f60fc757c29828f1f:reports/:data <- ddply(x, .(as.factor(y), summarise, mean(count))
2c975e1faee880545546646648f5be2b55f60fc757c29828f1f:reports/:data <- ddply(x, .(as.factor(y), summarise, mean(count))
2c975e1faee880545546646648f5be2b55f60fc757c29828f1f:reports/:data <- ddply(x, .(as.factor(y), summarise, mean(count))
2c975e1faee880545546646648f5be2b55f60fc757c29828f1f:reports/:data <- ddply(x, .(as.factor(y), summarise, mean(count))

I sift through the code and eventually find the bit I was looking for. I copy the relevant bit of code from Terminal and paste it back into my R script. Before the code is useable, I need to delete this bit: 2c975e1faee880545546646648f5be2b55f60fc757c29828f1f:reports/:

At the moment, this feels like a rather slow and clunky way of re-using old, version controlled code, and I might be better off using Rhistory.

Is there a faster way of getting version controlled code out of git and back into a R script in RStudio?

Edit
Report