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

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

问题描述

我在笔记本电脑上创建了一个本地 Git 存储库,然后将源代码推送到 Heroku,创建了一个远程分支.经过几天的提交和推送,我需要回滚到较早的提交.这就是我所做的.

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 

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

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.

推荐答案

当您检出直接提交名称(使用提交对象的 SHA-1 哈希值)而不是检出分支名称时,您最终会得到分离头".HEAD 是跟踪当前签出内容的参考".当您直接签出提交而不是分支(它未附加到任何分支)时,它会变得分离.分离存储库的 HEAD 时不会更新任何分支.您可能会认为分离的头部状态就像检查了一个匿名分支.

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.

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

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

  1. 要将当前 HEAD 保存在 new 分支中,请执行以下操作:

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

git branch <new-branch-name>

  • 要覆盖现有分支,您需要使用--force:

    git branch --force <existing-branch-name>
    

  • 然后,通过检查新的/更新的分支重新附加您的存储库的 HEAD:

  • 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)

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

    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.

    将来,如果您想将当前分支回滚"到之前的某个提交,您应该使用此而不是分离存储库的 HEAD:

    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>
    

    这会将当前分支(或您分离的 HEAD,如果它已经分离)重置为命名提交,并使索引和工作树反映该提交(即它丢弃自指定提交以来的任何提交以及任何未提交的内容).

    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).

    分离的 HEAD 状态对于重新访问旧状态很有用,有时对于您不确定是否会保留的短期工作非常有用.除此之外,您可能想避免它.

    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天全站免登陆