创建分支后恢复许多提交
我正在使用 git 来管理我的项目,但我对此类程序没有太多经验,因此我经常不正确地使用它们(例如:我仅在一次提交中提交了许多(不相关的)更改)。我正在尝试更好地利用它们。
顺便说一句,我注意到我开始开发我的项目的扩展,它将更好地适合分支。因此,我从 git gui 创建了一个新分支,它是主分支的副本。 现在我想将主控恢复到我所做的最后一次提交,它与项目无关。我知道这个提交是什么,但我不知道如何将所有提交从 HEAD 恢复到这个提交,而且我不知道这是否会影响分支(失去所有新工作将是一种真正的痛苦..)
那么,我该怎么办?
PS:通常我使用git gui,但使用git bash没有问题。我使用 win7,我正在 eclipse 中管理一个 java android 项目
i'm using git to manage my project, but i'm not much experienced in this kind of programs, so often i use them improperly(eg: i commit many (unrelated) changes in only one commit). I'm trying to using them better.
Btw i noticed that i started to develop an extension of my project that would be better fitting into a branch. So from the git gui i created a new branch that's a copy of the master.
Now i want to revert the master to the last commit i made that it is not relevant to the project. I know what this commit is, but i don't know how to revert all the commits from HEAD to this one, and i don't know if this will influence the branch(it would be a real pain to lose all the new work..)
So, how can i do?
Ps: usually i use git gui, but i have no problem in using git bash. I use win7 and i'm managing an java android project in eclipse
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已创建分支,请更改回主分支并使用 git reset --hard commitid 将其重置为所需的提交。现在“master”已设置为此提交,并且分支仍然指向您之前配置的提交。
分支名称是特定提交的引用或备用名称。重置允许您更改参考指向的提交并强制工作树匹配(使用--hard)
If you have your branch created, change back to the master and reset it to the desired commit with
git reset --hard commitid
. Now 'master' is set to this commit and branch still points to the commit you had it configured for previously.Branch names are references or alternate names for specific commits. reset allows you to change the commit that your reference points at and force the working tree to match (with --hard)
对
master
分支的更改不会影响新分支的历史记录。如果您想将
master
的 HEAD 更改为特定提交,请使用 重置:如果您的事件顺序是:
如果您只想让
master
回到上一次提交之前,请使用 重置:如果您的事件顺序是:
master
中)。您只想从
master
删除big Change
提交,同时保持所有其他提交完好无损,请使用 恢复:如果您的事件顺序是:
master
中删除)。并且您想要删除所有最近的提交,包括来自
master
的big Change
,请使用 重置:Changes to the
master
branch will not affect the history for your new branch.If you want to change
master
's HEAD to be at a specific commit, use reset:If your sequence of events were:
And you just want to get
master
back to before the previous commit, use reset:If your sequence of events were:
master
).And you just want to remove the
big change
commit frommaster
while leaving all other commits intact, use revert:If your sequence of events were:
master
).And you want to remove all recent commits up through and including
big change
frommaster
, use reset: