[英]How can I reset my branch to a commit I created while in detached-HEAD mode?
I've got no idea what the Git graph looks like in this instance, so before I accidentally lose any code, I figure I'll ask for help. 我不知道这种情况下的Git图是什么样子,所以在我意外丢失任何代码之前,我想先寻求帮助。
I committed some code that broke things, so I checked out a previous commit to look at what went wrong. 我提交了一些会破坏性能的代码,因此我签出了先前的提交以查看出了什么问题。
commit 87dfs7f6d6fs8 (latest commit on master)
commit 7fe7f86we6f8d6 <-- checked out this guy
However, I forgot to recheckout master
to fix the problem, and instead fixed it in the detached-HEAD state. 但是,我忘记了重新检出master
来解决此问题,而是将其修复为HEAD分离状态。
So, now, my Git history looks something like this... (I guess) 所以,现在,我的Git历史看起来像这样...(我猜)
commit 87dfs7f6d6fs8 (latest commit on master)
|--- commit 6f5dsf5d65f <-- New commit (currently checked out)
commit 7fe7f86we6f8d6 <-- checked out this guy
What I'd like to do is completely get rid of the topmost commit and keep the changes that I made. 我想做的是完全摆脱最重要的提交,并保留我所做的更改。 I think to do this I need to reset --hard
to the commit hash I'm currently on, right? 我认为要执行此操作,我需要reset --hard
为我当前所在的提交哈希,对吗?
So, it'd be: 因此,它将是:
git reset --hard 6f5dsf5d65f
Where commit 6f5dsf5d65f
is the commit I did in the detached-HEAD state. commit 6f5dsf5d65f
是我在HEAD分离状态下所做的提交。 Is this right..? 这是正确的吗..?
What I'd like to do is completely get rid of the topmost commit [
87dfs7f6d6fs8
] and keep the changes that I made. 我想做的就是完全摆脱最上面的提交[87dfs7f6d6fs8
]并保留我所做的更改。
If I understand your problem correctly, you basically need to 如果我正确理解了您的问题,那么您基本上需要
master
branch point to commit 6f5dsf5d65f
instead of 87dfs7f6d6fs8
, 使master
分支点提交6f5dsf5d65f
而不是87dfs7f6d6fs8
, Check whether you need to create a stash by running git status
. 检查是否需要通过运行git status
创建存储。 If it tells you that you have a clean working state, run 如果它告诉您您的工作状态很干净,请运行
git checkout master # important!
git reset --hard 6f5dsf5d65f
Otherwise, run 否则,运行
git stash save
git checkout master # important!
git reset --hard 6f5dsf5d65f
git stash pop
Note that, in either case, you need to check out master
before you can reset it; 请注意,无论哪种情况,您都需要先检出master
才能重置它; running git reset
while in detached-HEAD state would only move HEAD
. 在分离HEAD状态下运行git reset
只会移动HEAD
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.