last day (16 days later) » 

3:30 AM
0
A: How do I revert to a previous git in R studio?

ConduitIf you wish to only revert those files, and to do so on the master branch, then you should: Check out the master branch Check out only those file(s) from the previous commit Stage the changes (the reverted files) Make a new commit This will look something like the following: git checkout mas...

 
I am pretty new to git so maybe I misunderstood the way it works: I thought it was possible to simply go back to a previous commit, but you are saying I should check out those files an commit again. Thus basically I cannot simply step back, correct?
 
You can go back to a previous commit, but you would lose any other changes made since that commit (i.e. not just the ones to those files). Is that desirable?
If so, you need to make the master branch pointer point to an older commit. The command is dangerous, and will discard all changes you've made in your working directory git reset --hard [commit hash]. The commits you've made since the one specified will still be in the repo, but will no longer be part of the master branch.
@Dambo - all that said, it is much safer to just move forward as shown in my answer. No weird side effects, just a new commit that changes the files to their old state.
 
Ok say I have commits 1,2,3,4. I am now in commit 1, the last. I would like to see my files as if I was in commit 2. You are saying instead that to see everything as if I was in 2, I should either delete 1 or commit 2 to a new commit say '0'. No direct way to just go to commit 2 then?
 
@Dambo - I'm confused - do you just want to view the files, recover the files, or completely undo the last commits? Have you made a commit since the files were deleted?
 
No commits after deleting those files, however my last commit had those file. I thought that by checking out that commit in which those files existed, they should reappear in my current session (where I have deleted those files).
 
3:39 AM
Ah! I think I understand now. To fix the problem you will have to fix your detached head state, unstage the removal of those files, and then check out the old versions of those files.
The commands to do those will be:
git checkout master
git reset -- path/to/file.txt (for each file)
git checkout -- path/to/file.txt (for each file)
After that, try running git status to make sure everything looks okay
 
 
12 hours later…
3:39 PM
Thanks, I forgot about the chat. I am still very confused. First of all, I am not sure if that would make any difference but I am working with R studio. Now, looking at your code: I would expect 'git checkout master' to recover any file in the same form as it was committed. However, if I randomly type something after committing, and then I try to go back to the committed form of the file using 'git checkout master' I get "already on master".
I took the online class and udacity and with a single txt files I recall using 'checkout' to ripristinate previous versions of the file
 
 
6 hours later…
9:56 PM
Imagine that at any given time, git has three versions of the files in your repo - a version pointed to by HEAD (generally a reference to the last commit of a branch), a version that is staged for changes (the last version for which you ran git add ...), and the version currently in your working directory.
Basically the goal is to restore the three versions of those files to their original state
Checking out the other commit detached HEAD from the pointer to the current state of the master branch.
So we need to restore the pointer to that branch (git checkout master)
Since those files were deleted, they've been marked for removal in the staged changes. We need to make sure that is undone, too (git reset -- path/to/file.txt)
Finally we can restore the files from a previous commit (git checkout -- path/to/file.txt)
So the end result is that you are on the master branch, no deletions have been staged, and the files in your working directory are restored.
As for working with R Studio: I'm not positive, but I'd bet that won't affect anything unless you're using it as a gui for dispatching commands to git, or something like that. If you're issuing console commands I'd guess you're fine.
 
10:19 PM
Does that help clarify things, @Dambo?
 

  last day (16 days later) »