Git签出旧提交,并进一步进行新的提交 [英] Git checkout old commit, and further make new commits
问题描述
我正在研究一个项目,其中我做了一些改变,并且推到起源的主人,只是意识到主人有一些重大的错误,因此我检查了一个特定的旧提交,在同一主分支中使用
git checkout commit_name
之后,我开始进一步工作,不断添加并提交,现在我迷失了如何保持以下新功能提交,并且不会丢失更早的(马车)主。基本上如何回到正轨。
我尝试使用 git push -u origin master
,但它返回所有最新的
,并且没有任何东西被推送to bitbucket。
我想你是在分离的头部
。当您执行 git checkout commit_name
时,您更新了本地资源库以检出 commit_name
的代码,但您不在任何科。你在自由式的方式,只能做有限的行动。您需要返回您的 master
分支。
-
git checkout -b branch_tmp
移动到新创建的分支branch_tmp
-
git rebase master
将最后一次提交应用于master -
git checkout master
-
git merge branch_tmp
更新您的master
分支, code> branch_tmp -
git push origin master
-
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.
git checkout -b branch_tmp
to move to the new created branchbranch_tmp
git rebase master
to apply your last commits on top of mastergit checkout master
git merge branch_tmp
to update yourmaster
branch with commits done previously and present onbranch_tmp
git push origin master
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屋!