r-lib / gert

Simple git client for R
https://docs.ropensci.org/gert/
Other
146 stars 31 forks source link

git checkout #147

Open pcinereus opened 3 years ago

pcinereus commented 3 years ago

Is there a way to checkout a specific commit? - e.g. detach the head. In git this would be git checkout # where # is the commit hash.

jeroen commented 3 years ago

Not with detaching I think. The easiest way may be to create a temporary branch?

git_branch_create('mytest', ref = '680d004c14bae67b2cc23a0632230edee4d4ade6')

Which will automatically do the checkout. Or you can git_reset to the hash.

pcinereus commented 3 years ago

Thanks for your reply. The motivation is simply to return to a previous "Version" of the code in order to re-run the code as it was at that point (to reproduce figures etc from publications) before going back to HEAD to continue on. Full disclosure, I was hoping to weave gert into teaching materials for stats students who are comfortable with R and Rstudio, but less so with terminal. gert does fill a couple of gaps that are left open by Rstudio (eg tagging, git reset), but I find both git revert and git checkout are used frequently as well.

allenbaron commented 2 years ago

Is there any way to checkout can be added without requiring the creation of a new branch?

I'd like to be able to checkout a branch, tag, or commit and then return the HEAD to its original state. git_branch_checkout() works fine when the initial HEAD is on a branch but not when the initial state of the repository is itself a detached HEAD. Since every checkout requires a branch it's not possible to return to a detached HEAD state without creating a new branch and that new branch can't be deleted because it must be checked out.