Git checkout – switching back to HEAD

I’ve been doing my project while at some point I discovered that one thing stopped working. I needed to look up the state of my code when it was working correctly, so I’ve decided to use git checkout (because I wanted to check-something-out). And so I’ve done

git checkout SHA

couple times while going back to point from which I can’t go to HEAD, the output is following:

  • Why does Git tell me “Not currently on any branch” after I run “git checkout origin/<branch>”?
  • is there a command in GIT that has the options of “git add -p” and “git checkout -p” COMBINED?
  • Checkout svn using gradle
  • How do I do an exclusive checkout in SVN?
  • Reducing the size of the .svn folder
  • LibGit2Sharp CheckoutPaths()
  • git checkout SHA-HEAD
    
    error: Your local changes to the following files would be overwritten by checkout:
        [list of files]
    Please, commit your changes or stash them before you can switch branches.
    Aborting
    

    I am pretty much sure I have NOT changed anything. The command

    git checkout master
    

    gives the same output.

    Is there a way to go back to HEAD?

    What is the safe way of “jumping over” history commits?

  • Git/GitHub can't push to master
  • Run git server on local network
  • How does Github, Gitlab, Gitosis, etc.. knows which user is logged in?
  • Why are ignored files not being ignored?
  • GIT hook post-receive and remote repository git pull
  • ssh config not working. Permission denied (publickey)
  • One Solution collect form web for “Git checkout – switching back to HEAD”

    You can stash (save the changes in temporary box) then, back to master branch HEAD.

    $ git add .
    $ git stash
    $ git checkout master
    

    Jump Over Commits Back and Forth:

    • Go to a specific commit-sha.

      $ git checkout <commit-sha>
      
    • If you have uncommitted changes here then, you can checkout a new branch, Add, Commit, Push the current branch to the remote.

      # checkout a new branch, add, commit, push
      $ git checkout -b <branch-name>
      $ git add .
      $ git commit -m 'Changes in the commit'
      $ git push origin HEAD        # push the current branch to remote 
      
      $ git checkout master         # back to master branch now
      
    • If you have changes in the specific commit and don’t want to keep the changes, you can do stash or reset then checkout to master (or, any other branch).

      # stash
      $ git add -A
      $ git stash
      $ git checkout master
      
      # reset
      $ git reset --hard HEAD
      $ git checkout master
      
    • After checking out a specific commit if you have no uncommitted change then, just back to master or other branch.

      $ git status          # see the changes
      $ git checkout master
      
      # or, shortcut
      $ git checkout -      # back to the previous state
      
    Git Baby is a git and github fan, let's start git clone.