简体   繁体   English

如何在GIT中撤消6次本地提交?

[英]How do I undo 6 local commits in GIT?

I am new to GIT. 我是GIT的新手。 I tried committing code to my brach. 我尝试将代码提交到自己的分支机构。 The commit would work fine but push would fail because I was not adhering to the standard push comments (not the issue here) . commit可以正常工作,但push会失败,因为我没有遵循标准的 push注释(此处不是问题)。 Now, I have 6 failed commits. 现在,我有6个失败的提交。 git status says : Your branch is ahead of 'branchX' by 6 commits. git status表示: 您的分支比“ branchX”领先6次提交。 How can I undo all my failed commits? 如何撤消所有失败的提交?

Most probably, git reset --hard <to-what-point> , but please create a local branch first on your HEAD, or you will have a hard time finding your commits afterwards. 很有可能是git reset --hard <to-what-point> ,但是请先在HEAD上创建一个本地分支,否则之后将很难找到提交。 Once you are sure they are not needed any more, just delete the branch. 一旦确定不再需要它们,只需删除分支。

Also, please note that if your problem is just in bad commit messages, then git rebase --interactive will let you easily rewrite the commits and correct messages. 另外,请注意,如果您的问题仅在于错误的提交消息,那么git rebase --interactive将使您轻松地重写提交并更正消息。

git reset command should deal with it. git reset命令应该处理它。
It will undo the last 6 commits from the head. 它将撤消从头开始的最后6次提交。
Note that you will lose your current changes in this local repository (if any) 请注意,您将丢失此本地存储库中的当前更改(如果有)

$ git reset --hard HEAD~6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM