With git reflog
check which commit is one prior the merge ( git reflog
will be a better option than git log
).
(使用git reflog
检查哪个提交是合并之前的提交( git reflog
比git log
更好的选择)。)
Then you can reset it using: (然后您可以使用以下方法重置它:)
git reset --hard commit_sha
There's also another way:
(还有另一种方法:)
git reset --hard HEAD~1
It will get you back 1 commit.
(它将使您退回1次提交。)
Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state .
(请注意,任何已修改和未提交/未破坏的文件都将重置为其未修改状态 。)
To keep them either stash changes away or see --merge
option below. (要保留它们,可以--merge
更改,或参见下面的--merge
选项。)
As @Velmont suggested below in his answer, in this direct case using:
(正如@Velmont在下面的回答中所建议的,在这种直接情况下,使用:)
git reset --hard ORIG_HEAD
might yield better results, as it should preserve your changes.
(可能会产生更好的结果,因为它可以保留您的更改。)
ORIG_HEAD
will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself. (ORIG_HEAD
将在合并发生之前直接指向一个提交,因此您不必自己寻找它。)
A further tip is to use the --merge
switch instead of --hard
since it doesn't reset files unnecessarily:
(另一个提示是使用--merge
开关而不是--hard
因为它不会不必要地重置文件:)
git reset --merge ORIG_HEAD
--merge
( - 合并)
Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (ie which have changes which have not been added).
(重置索引并更新工作树中<commit>和HEAD之间不同的文件,但保留那些索引和工作树中不同的文件(即,尚未添加的更改)。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…