问题
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.
git checkout -b branch_tmpto move to the new created branchbranch_tmpgit rebase masterto apply your last commits on top of mastergit checkout mastergit merge branch_tmpto update yourmasterbranch with commits done previously and present onbranch_tmpgit push origin mastergit branch -d branch_tmpto 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