Git结帐< SHA>和Heroku [英] Git checkout <SHA> and Heroku

查看:167
本文介绍了Git结帐< SHA>和Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在笔记本电脑上创建了一个本地Git仓库,然后将源码推送到Heroku,创建了一个远程分支。经过几天的提交和推送后,我需要回滚到之前的提交。这是我做的。

  cd< app root> 
git checkout 35fbd894eef3e114c814cc3c7ac7bb50b28f6b73

有人告诉我,结帐创建了一个新的工作树,而不是分支本身,所以当我将回滚更改推送到Heroku时,它说所有内容都是最新的,没有任何内容被推送。我如何解决这种情况?感谢您的帮助。

解决方案

当您签出直接提交名称(使用提交对象的SHA-1哈希)而不是检出一个分支名称,最终得到一个分离的HEAD。 HEAD是跟踪当前检出内容的ref。当你直接签出一个提交而不是一个分支(它没有连接到任何分支)时,它会变成分离的。分离存储库的HEAD时不会更新分支。您可能会想到分离的头部状态,就好像您签出了一个匿名分支。






要重新连接存储库的HEAD,你需要将当前HEAD保存为一个分支,并检查该分支:


  1. 要将当前HEAD保存在<

      git分支<新分支名称> 


  2. 要覆盖现有的分支,您需要使用 --force

      git branch --force< existing-branch-名称> 


  3. 然后,通过检出新的/更新的分支来重新连接存储库的HEAD:

      git checkout< branch-name> 

    (其中<分支名称> < new-branch-name> <现有分行名称> 相同,具体取决于你使用了以上两个命令中的哪一个)


    这个序列( git branch 指向当前的HEAD提交,然后 git checkout 更新的分支)将继承您工作索引中可能存在的任何未提交的内容, /或树。






    将来,如果您想将当前分支回滚您应该使用而不是来分离您的存储库的HEAD:

      git reset --hard< commit> ; 

    这将重置当前分支(或已分离的HEAD,如果它已经分离)提交,并使索引和工作树反映该提交(即它会抛出任何提交,因为指定的提交以及任何未提交的内容)。



    分离的HEAD状态对重新访问旧国家有用,有时对于你不确定你会保留的短期工作很有用。除此之外,你可能想避免它。


    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 earlier commit. Here's what I did.

    cd <app root>
    git checkout 35fbd894eef3e114c814cc3c7ac7bb50b28f6b73 
    

    Someone told me that doing the checkout created a new working tree and not the branch itself, so when I pushed the rollback changes to Heroku, it said everything is up to date and nothing was pushed. How do I fix this situation? Thanks for your help in advance.

    解决方案

    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.

    这篇关于Git结帐&lt; SHA&gt;和Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆