Andy Cass
Andy Cass

Reputation: 446

Git I have checked out the master but I want to revert this

I Have been using GIT for a project on a local machine, I don't know that much about git but it has been working well, I have periodically been adding and committing to the repo i.e.

git add .

git commit

I have also been checking out to previous versions after making mistakes using :

```git checkout 7640ac36f0a5cfe28bce7f8e5e5fc84f71ca6d71```

I have just created a repository in github and I have tried to send my project to github following the instructions I tried to branch the project (As instructed)

git branch -M main

this gave me an error something about a Detached HEAD.

I then followed this on SO Fix a Git detached head?

  1. git branch my-temp-work
  2. git checkout master
  3. git merge my-temp-work

I have an error saying

error: Your local changes to the following files would be overwritten by merge:
  .idea/codeStyles/Project.xml .idea/codeStyles/codeStyleConfig.xml .idea/encodings.xml

Now I am at a much earlier version then I wish to be at, How can I undo this to get back to my previous version and then make the HEAD not detached so that I can add to the remote Git Repo..

The Output from: git log --graph --oneline --all --decorate

* 0ade9cbf (my-temporary-work) This was the last commit before moving to remote repo
* bc8c309f Commit before updating to android x
* 6335ac8f updated the media player tidied things up still a work in progress.
* fd08c4ab save before removing concatenating media source
* d2869c0b Updated libs including exoplayer
* 42d2fc20 GC some memory leaks found and hopefully rectified...
* b06759f4 added leak canary to detect memory leaks
* ef380de0 removed the unnecessary play fun from main and fav activities as it is implemented in parent class...
* 7640ac36 commit after changing the on button pressed interface in audio fragments to inherit from the base audio fragment
* 1377bdec changed exoplayer fragment to inherit from base audio fragment...
* e35ff716 Commit before implementing bottom sheet factory...
* eeedb7b3 good restore point still not really fully happy with play pause in playlist also more button not working yet
* e5f0bc98 playlist fragment works better now good restore point still work to do to simplify it...
* 24b666f2 playlist slightly improved now it is more dynamic getting the current items in the playlist need attention tho....
* 60886c2a still working on playlist going to be a hybrid of the music live adapter and playlist adapter this will utilise diff utils and swipe delete
* e6415800 Fixed a few compilation errors after changing from java to kotlin small changes of the companion objects
* a24c707e Good clean up most fragments inherit from baseAudioFragment where delete and alter metadata is taken care of....
* bb9d93a2 updated a base audio fragment to remove duplicated code.
* d9d765fa deleting the media source doesnt throw an error now
* 7ff42182 Delete looks like it works while its playing too
* 61f99121 the delete fun in the exoplayer fragment throws a null pointer error this is semi sorted but an error is thrown if a new activity is started
* cb51b6c2 Changed Exoplayer Music service to Kotlin
* 0139aeb9 clean up the fav stopped working now is ok
* eb7e4f2f Tidying up the Exoplayer Fragment changed to Kotlin
* 09661181 Delete whilst in playlist now works...
* 2bce752c removed some repetative code from activities for songs and placed it in base activity tested works fine
* 54e04e3b added ISongExoPlayerCallback delete callback this will delete an id from the playlist before deleting the file from the media store
* 4d9f242a commit after changing min api from 23 -> 30 and target 30
* ab326226 Little Tidy up...
* f148babc Getting there the delete works now this will be a model for the edit and add new file
* 679df68e Commit before change metadata change
* b93006fd Lots of changes
* bdfd2a59 was trying to complete the change metadata class but i have had to return to change item dialog
* a307b90d SdCard Fragment changed to only update the intent service when the item has downloaded fully
* 68f84f7c sorted a few tings out sd card and downloads in api 29 play now
* 48ca5fcf the sd card downloads play now using the url the artist etc still needs a coat of looking at...
* d32506bc Audio Books and Podcasts works now...

The Output from: git branch -vv

* master 277f6666 Reverting to old project my-temporary-work 0ade9cbf This was the last commit before moving to remote repo

Upvotes: 0

Views: 87

Answers (1)

Andy Winarko
Andy Winarko

Reputation: 755

Try this one,

  1. git reflog , this will show all of your commit
  2. Find your commit
  3. git reset --hard <hash-id>

For further research :

Upvotes: 1

Related Questions