Git checkout and Heroku

前端 未结 2 1245
野的像风
野的像风 2020-12-17 02:26

I created a local Git repo on my laptop and then pushed the source to Heroku creating a remote branch. After a few days of commits and pushes, I need to rollback to an earli

相关标签:
2条回答
  • 2020-12-17 02:48

    You want to reset:

    git reset --hard 35fbd894eef3e114c814cc3c7ac7bb50b28f6b73
    0 讨论(0)
  • 2020-12-17 02:55

    When you checkout a direct commit name (using the SHA-1 hash of the commit object) instead of checking out a branch name, you end up with a “detached HEAD”. HEAD is the “ref” that keeps track of what is currently checked out. It becomes detached when you directly checkout a commit instead of a branch (it is not attached to any branch). No branches are updated when you detach a repository's HEAD. You might think of the detached head state as if you had an anonymous branch checked out.


    To reattach your repository's HEAD, you will want to save the current HEAD as a branch and check that branch out:

    1. To save the current HEAD in a new branch do this:

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

      git branch --force <existing-branch-name>
      
    3. Then, reattach your repository's HEAD by checking out the new/updated branch:

      git checkout <branch-name>
      

      (where <branch-name> is the 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 ref point to the current HEAD commit, then git checkout that updated branch) will carry forward any uncommitted content that you might have in your working index and/or tree.


    In the future, if you want to ‘roll back’ the current branch to some previous commit, you should use this instead of detaching your repository's HEAD:

    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 the working tree reflect that commit (i.e. it throws away any commits since the specified commit along with any uncommitted content).

    The detached HEAD state is useful for revisiting old states, and sometimes for short-term work that you are not sure you will keep. Other than that you probably want to avoid it.

    0 讨论(0)
提交回复
热议问题