Git checkout old commit, and further make new commits

巧了我就是萌 提交于 2019-12-23 23:53:24

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/39371098/git-checkout-old-commit-and-further-make-new-commits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!