Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Merged and Deleted Progress

+13 votes
Okay so it appears that I may have merged and overwritten some strings that we had created... Does GitHub save the old unmerged file anywhere for me to access and get those strings back?

Where would I find it?
asked Apr 20, 2015 in Spring 2015 by Erik Aksland (100 points)

3 Answers

+7 votes
Best answer


I believe you can find the previous version of the file in the commits section. If you find the correct version you can either copy the correct information manually from the page. Or you can use Git Bash to checkout that file.

git checkout abcde file/to/restore

Where abcde is the commit identifier and the file/to/restore is the path to the file you want to commit.

answered Apr 20, 2015 by Ethan Wojcinski (100 points)
selected Apr 21, 2015 by Erik Aksland
+4 votes
If you want to go back to the un-merged version, you can look at your commits on github then find the commit before you had an issue. Click to copy the full SHA, then in Android Studio, go to VCS>GIT>Reset HEAD. In the To Commit box, paste the SHA and select Reset Type: Hard. This will give you exactly what was on git up to and including that commit. Note that this will get rid of any work you have done since the commit you are resetting to; different reset types such as Mixed and Hard may lead to mixed results.
answered Apr 20, 2015 by Daniel Shultz (100 points)
+2 votes
A key decider is:  were the strings that you had created ever *committed* to the repository?  

* If they were just local *untracked* files on your computer, and you overwrote them during a merge that happened during an "unstash" (e.g. "Update Project"), then you might be out of luck.

* But, if you these strings you want back were ever committed to the repository (even just your local repository, not GitHub), then you should be able to recover them.  

(Other answers are suggesting looking on GitHub, which is fine, but that won't work if you only had committed the strings locally, and never PUSHED them.)

Inside Android Studio itself, you should be able to right click on the file that lost the data, and view previous versions (maybe under the "git" menu?) of that file.  You can then copy the pieces of the file that you need back into the current version, and make a new commit with those changes.
answered Apr 25, 2015 by Forrest Stonedahl (100 points)