Undo git commit in Rstudio that is too big to push
Asked Answered
F

3

22

I am very new to github and am trying to incorporate it into my work for the first time. I am working in RStudo, using the commit and push buttons in the gui. I put some of my data in the folder on my computer that I am working out of. I made a few commits, then I commited that data, and then I made another few commits. Then I tried to push the whole thing to github. However, I got an error message saying:

remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.        
remote: error: Trace: f4a84c3a176d2c77039d041a21c0c455        
remote: error: See http://git.io/iEPt8g for more information.        
remote: error: File S_Fulltaxonomy.csv is 158.06 MB; this exceeds GitHub's file size limit of 100.00 MB        
To [email protected]:moanam/paper.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:moanam/paper.git'

My branch is now ahead of origin/master by 10 commits, with the problem commit somewhere in the middle.

I have looked for solutions to this and have found posts like undo commit in middle of Git history, How to modify existing, unpushed commits? and How to remove a too large file in a commit when my branch is ahead of master by 5 commits

However, the solutions to this are a line of code where the original asker is supposed to substitute a few words and run it somewhere. I really am very new to this and have no idea where to run all this code, what to substitute and how to find and change the problem commit in my work. How do I do this? Or is there a gui based version of undoing the commit in RStudio? Or could someone please explain exactly how to use the code?

I know that this is probably a very simple question and I am sorry for wasting your time with it. However, I have genuinely spent quite a while looking already and can't find anything simple enough for me to work with! There is always too much knowledge assumed. Thanks for your help!

Foyer answered 18/10, 2016 at 18:41 Comment(0)
D
20

There is an easier way.

I am not sure how to do it via Rstudio but you can do this instead.

Go to the command line --> navigate to the directory of your project

Once inside type:

git reset HEAD~

If you want to undo two commits type it twice.

This will undo the last commit but won't delete any files. Therefore files will all reappear in the staged menu. After that, re-commit without the large files then push again and all should be ok.

Distributary answered 27/7, 2020 at 15:36 Comment(2)
In RStudio it's basically the same: go to git tab > gear icon > shell. That brings up a shell and you can use the git reset HEAD~ command.Schoenberg
When using git within RStudio, it's important not to commit too much at a time. Committing more than a few dozen files via RStudio's GUI for git seems to be hazardous. RStudio puts up a warning screen asking me if I want to continue, but without providing any clue that I could decipher about how I could abort the oversized commit. In the current version of RStudio, you can get a command shell by selecting "Terminal" in the gear icon of the git tab... and the shell is running in a window called Terminal.Electrician
F
14

I worked it out. So, for anyone else:

First, back up all your files to another location (the original ones will be deleted)

You can open the command line from RStudio from the Git tab and then going to More and then Shell.

Type in git reset --hard origin/master This will undo all commits and go back to what you had at your last push

Copy the files back to your working directory (replacing the older versions) and re-commit all the changes you had made since then. Make sure not to copy the rhistory file or it will redo all your previous commits.

Foyer answered 19/10, 2016 at 0:42 Comment(3)
If you want to know how many commits since your latest commit you have, you can see them by: Go to Rstudio | git tab | master (icon). You get a message showing something like: ' M R/your_changed_file.R Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) 'Branson
Even when I delete rhistory, the old commits are still there. Any idea why?Frederigo
Much easier to use git reset HEAD~ in a terminal as suggested by Adam Waring, especially if the big commit is the latestMaximilianus
K
1

So I think you are asking a couple of questions here:

  1. A commit with a big file size: You will need to exclude these files in your .gitignore file so they will stay in your local folder but won't be pushed into your github repository. More on that here: https://git-scm.com/docs/gitignore
  2. Reverting a git commit: You can use the commands you posted but you are right you should probably know what you are doing. So invest a little time and read through the basics of git.
  3. Looking for a GUI: You can work with GitGUIs, there is version for Mac and Windows https://desktop.github.com/. But since you will have to understand the basics of git anyway, imho the GUI doesn't make it much easier. Stick with it and you will understand this kind of stuff in no time.
Kailakaile answered 18/10, 2016 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.