How to get back to most recent version in Git ?

How to get back to most recent version in Git ?

Asked on January 10, 2019 in Git.
Add Comment


  • 3 Answer(s)

       git checkout master to do the trick and  back two versions, git checkout HEAD~2, but better to create a temporary branch based on that time, so git checkout -b temp_branch HEAD~2

    Answered on January 10, 2019.
    Add Comment

    To a specific commit, git creates a detached branch.

    $ git branch
    
    

    few things see like ,

    * (detached from 3i4j25)
    
    master
    
    other_branch
    
    

    In the master branch  head you need to checkout to your master branch again:

    $ git checkout master
    
    

    In the detached branch command will automatically delete.

    git checkout doesn’t work, to lose code git  requires you to deal with these files.

    Stash your modifications

    $ git stash
    
    

    Discard the changes reset-ing the detached branch:

    $ git reset --hard
    
    

    Create a new branch with the previous modifications and commit them:

    $ git checkout -b my_new_branch
    
    $ git add my_file.ext
    
    $ git commit -m "My cool msg"
    
    
    $ git checkout master
    
    
    Answered on January 10, 2019.
    Add Comment

    If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit. To fix the detached head do git checkout <current branch>

    Answered on February 20, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.