0

I'm having trouble rolling back to a previous commit to Github using Android Studio.

When using the 'checkout' option some of my project changes back to how it was, however all new classes remain and some but not all new changes also remain.

I want to roll back so my project is exactly as it was when I committed it, with no new classes or changes to the code remaining.

mattstack
  • 51
  • 1
  • 12

2 Answers2

2

On the bottom of Android Studio, click Version control, then Log, rightclick the commit you want to reset to, click reset current branch to here, click hard. You branch is now set to exactly how it was with that commit.

To update your remote branch on github, open the push window, click configure, check allow force push, if you're on master branch, remove it from the protected branches field. Close the configuration window. Then push as you're used to.

Reminder: every commit you made after the commit you reset to will be lost.

fweigl
  • 21,278
  • 20
  • 114
  • 205
-1

Basically git have two things stage and commit. It seems your newly files are untracked and not yet commited. If you need to add the files, use git add . to add all files at once or use git add <file_name> to add individual files. Then you can commit all your works i'll be present in that commit with all new files.

If you haven't staged your files whenever you checkout to new branch the unstaged files get into the new branch. Happening in your case.

All the things are based on cmd line instructions.

Ramkumar R
  • 497
  • 5
  • 11
  • This does not answer the question at all. – fweigl Sep 02 '17 at 14:52
  • I've committed my project to Github I now need to roll-back to that commit . The commit wasn't my last, it's about 3rd from last and doesn't contain any of the new files from my last commit. – mattstack Sep 02 '17 at 14:55