Git签出旧提交,并进一步进行新的提交 [英] Git checkout old commit, and further make new commits

查看:287
本文介绍了Git签出旧提交,并进一步进行新的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在研究一个项目,其中我做了一些改变,并且推到起源的主人,只是意识到主人有一些重大的错误,因此我检查了一个特定的旧提交,在同一主分支中使用



git checkout commit_name



之后,我开始进一步工作,不断添加并提交,现在我迷失了如何保持以下新功能提交,并且不会丢失更早的(马车)主。基本上如何回到正轨。



我尝试使用 git push -u origin master ,但它返回所有最新的,并且没有任何东西被推送to bitbucket。

解决方案

我想你是在分离的头部。当您执行 git checkout commit_name 时,您更新了本地资源库以检出 commit_name 的代码,但您不在任何科。你在自由式的方式,只能做有限的行动。您需要返回您的 master 分支。


  1. git checkout -b branch_tmp 移动到新创建的分支 branch_tmp

  2. git rebase master 将最后一次提交应用于master

  3. git checkout master

  4. git merge branch_tmp 更新您的 master 分支, code> branch_tmp

  5. git push origin master

  6. git branch -d branch_tmp 清理存储库

,我建议你看看记录历史记录,以了解执行的不同动作。



您可以找到更多有关分离头部的信息

FYI: I am using bitbucket to push my git to (I know not very important).

I was working on a project, wherein I made changes, and pushed to origin master, only to realise that master had some major bug, hence I checked out to a specific old commit, in the same master branch by using

git checkout commit_name

After that I started working further and kept adding and committing, now I am lost how to keep the following new commits, as well as not lose earlier (buggy) master. Basically how to get back on track.

P.S. I tried using git push -u origin master , but it returns Everything up-to-date, and nothing gets pushed to bitbucket.

解决方案

I guess you are on detached head. When you did git checkout commit_name, you updated your local repository to checkout the code of commit_name but you are not on any branch. You are in freestyle way and can only do limited action. You need to go back on your master branch.

  1. git checkout -b branch_tmp to move to the new created branch branch_tmp
  2. git rebase master to apply your last commits on top of master
  3. git checkout master
  4. git merge branch_tmp to update your master branch with commits done previously and present on branch_tmp
  5. git push origin master
  6. git branch -d branch_tmp to clean your repository

In any step, I advice you to have a look to log history to understand different action performed.

You could find more information about detached head there

这篇关于Git签出旧提交,并进一步进行新的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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