Git check out <SHA> and Heroku

I created a local Git repository on my laptop, and then dragged the source to Heroku, creating a remote branch. After several days of committing and pushing, I need a rollback to an earlier fixation. Here is what I did.

cd <app root> git checkout 35fbd894eef3e114c814cc3c7ac7bb50b28f6b73 

Someone told me that the check created a new working tree, not the branch itself, so when I discarded the rollback changes in Heroku, he said that everything was up to date and nothing was clicked. How to fix this situation? Thank you for your help.

+6
git ruby-on-rails heroku
source share
2 answers

When you check the direct commit name (using the SHA-1 hash of the commit object) instead of checking the branch name, you get a "separate HEAD". HEAD is a "ref" that tracks what is currently being verified. It disconnects when you directly check for a commit instead of a branch (it is not tied to any branch). No branches are updated when detaching the HEAD repository. You may think of the state of an individual head as if you had discovered an anonymous branch.


To reconnect your HEAD repository, you need to save the current HEAD as a branch and verify that the branch:

  • To save the current HEAD in the new branch, follow these steps:

     git branch <new-branch-name> 
  • To overwrite an existing branch, you need to use --force :

     git branch --force <existing-branch-name> 
  • Then secure your HEAD repository again by checking out the new / updated branch:

     git checkout <branch-name> 

    (where <branch-name> same as <new-branch-name> or <existing-branch-name> , depending on which of the above two commands you used)

This sequence ( git branch to make a reference point to the current HEAD commit, and then git checkout , updated branch) will transfer any uncommitted content that may exist in your working index and / or tree.


In the future, if you want to "drop the current branch to some previous commit", you should use instead to delete your HEAD repository:

 git reset --hard <commit> 

This will reset the current branch (or your detached HEAD, if it is already detached) to the named commit, and make the index and working tree reflect that commit (that is, it throws any commits from the specified commit along with any uncommitted content).

A disabled HEAD state is useful for reviewing old states, and sometimes for short-term work that you are not sure you will continue to do. Other than that, you probably want to avoid it.

+8
source share

Do you want to reset:

 git reset --hard 35fbd894eef3e114c814cc3c7ac7bb50b28f6b73 
+2
source share

All Articles