Reputation: 511
In Github Desktop I tried to commit and sync progress (like the fool I am, the last time I sent a commit was 4 days ago). I got an error message saying something like the push didn't succeed because one of the files exceeded 100MB (I am looking into adding this file to .gitignore). I checked my github account online to see if any of the files got pushed and none did. I checked on Github Desktop and couldn't see any of the files. I thought to myself this isn't good because if it's not detecting these changes anymore how am I supposed to attempt to commit them again? In a panic, I seen the following "Revert this commit" button thinking my changes would show up in Github Desktop again:
I pressed Revert this Commit and nothing noticeable happened. I think I then pressed Revert this Commit again on something (bad habit..). After more panic, I thought I would just make a small change to one of my files to see if the change shows up in Github Desktop. It did. So I committed and synced this change. I checked my github account online and I could see it was pushed successfully. This is where I realize I really messed up. I go back to Android Studio and I now realize that days of progress (a bunch of missing files) are gone (because being the idiot I am I waited days to back up). At this point I think I just lost the progress I made. I am wondering if there is anyway I can get it back? Upon doing a bit of research I attempted the git reflog command and I notice some words like revert and reset. I am wondering if this is enough to work with to get my progress back?
I am scared to attempt anything else without advice because as proven I like to wreck things =(
Upvotes: 2
Views: 1040
Reputation: 1
You have several options. The "revert this commit" button creates a revert commit that reverts everything in the latest commit. You can checkout the previous commit, reset to it, or revert the revert commit.
Firstly, you need to know the id of the previous commit. You can access it by the shortcut HEAD~1
or git log
and then copying the ID of the relevant commit.
Before reverting or resetting that commit , I suggest you to checkout the commit to make sure it contains the right files. git checkout <ID>
should do it. To return back to the branch, wolog you're on branch master
, just run git checkout master
.
Once you sure it is the right commit, you have two options.
git reflog
and some other GitHub's wrappers). Hard reset non-local changes is not a good habit, and requires a force push (replacing the remote's content with yours, overriding the changes in the remote).To do it, run git revert <ID>
, or git reset --hard <ID> and then
git pushor
git push --force` respectively, depended on your decision.
P.S. if your local changes get deleted somehow, you can always undo git pull
, git checkout
, git reset
etc. by running get reflog
and checking/resetting to the relevant commit ID.
ik my answer is probably too late, but others may encounter this question and want an answer.
Upvotes: 0