git rebase吃了我的提交!翻译"git reflog"输出给我吗? [英] git rebase ate my commits ! Translate 'git reflog' output for me?

查看:421
本文介绍了git rebase吃了我的提交!翻译"git reflog"输出给我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了五次提交,我想在推动它们之前将它们全部变成一次提交.由于某种原因,我决定尝试使用不同于通常使用的方法来进行此操作.

I had done five commits and I wanted to make them all into one commit before pushing them. For some reason I decided to try doing this by a different means than I usually use.

FWIW:我试图按照此处的说明 http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html .

FWIW: I was attempting to follow the instructions here http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html .

我将在下面进行详细介绍,但您可能想跳到我将git reflog输出放在其中的问题的底部,因为我怀疑这在这里​​很重要.

I'll put a lot of detail below but you might want to skip down to the bottom of the question where I put the output of git reflog because I suspect that's what's significant here.

这就是我所做的-所做的所有更改都被我做了:

So here's what I did - with all my changes committed I did :

git rebase -i HEAD~5

然后我看到了一个显示提交的文本编辑器,而我现在意识到,我错误地将"pick"的所有第一列值都更改为"squash".

and I was presented with the text editor which showed the commits and I, wrongly I now realise, changed all the first column values of 'pick' to 'squash'.

然后我看到一条错误消息.令我感到羞耻的是,我不记得错误消息的内容,但我认为它说的是诸如您没有要使用的内容"之类的内容.

I then saw an error message. To my shame I can't remember what the error message said but I think it said something like "You have no commit to use".

那时候我回到了提示,当我尝试重复:

At that point I was back to the prompt and when I try to repeat the :

git rebase -i HEAD~5

我收到消息:

It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr /home/foo/dev/bar/.git/rebase-merge
and run me again.  I am stopping in case you still have something
valuable there.

然后我阅读了此答案 https://stackoverflow.com/a/12163247/364088 建议这样做:

Then I read this answer https://stackoverflow.com/a/12163247/364088 which suggests doing :

git reset --soft HEAD^

我做到了(我希望没有).在我做完之后.

I did that (I wish I had not). After I'd done it.

git status

显示了许多未提交更改的文件,尽管

showed a number of files with uncommitted changes although

git diff

未显示任何更改.无论如何,然后我做了

showed no changes . Anyway I then did a

git commit

现在我在最近的五次提交中都失去了所有的技巧!

And now I have lost all my chnages in the last five commits !

git reflog

显示(这只是它的顶部):

shows (this is just the top of it):

3f80e4b HEAD@{0}: commit: Decorator demo added
1888dd9 HEAD@{1}: reset: moving to HEAD^
7d6228e HEAD@{2}: checkout: moving from master to 7d6228eb9b03d0c45acf7c66e662220213cf4fb9
705736f HEAD@{3}: commit: Snapshot commit - squash later
75db0c3 HEAD@{4}: commit: Snapshot commit - squash later
b70b50f HEAD@{5}: commit: Snapshot commit - squash later
d970a62 HEAD@{6}: commit: Snapshot commit - squash later
0f24e88 HEAD@{7}: commit: Snapshot commit - squash later
7d6228e HEAD@{8}: commit: Move some standard code into its own module and tidy up .
1888dd9 HEAD@{9}: commit: Early version of the decorators demo

所以事情是标记为快照提交-稍后压缩"的提交,这些都是我想要合并为单个提交的提交.

So the thing is the commits labelled "Snapshot commit - squash later" are the ones I wanted to merge into a single commit.

提交HEAD @ {2}和HEAD @ {1}是我在尝试合并那些快照提交-稍后压缩"的过程中所做的工作.提交HEAD @ {0}是我在重新设置基准并重置之后所做的提交.

The commits HEAD@{2} and HEAD@{1} are stuff I've done in the process of trying to merge those "Snapshot commit - squash later". The commit HEAD@{0} is the commit I did after the rebase and the reset.

以防万一,最后推送的提交是HEAD @ {8}.

In case it matters the last commit pushed was HEAD@{8}.

所以我想要返回到'705736f'提交,然后,理想的情况是仅这次使提交再次生效,使之生效!

So what I'd like is to get back to the '705736f' commit and then, ideally do the merging of commits again only this time make it work !

如果我能在快照提交-稍后再压缩"更改中恢复工作,我会很高兴.

I'd be quite happy if I could recover the work in the "Snapshot commit - squash later" changes.

不胜感激.

推荐答案

我的首选方法是在要取回的东西上贴标签,例如分支:

My preferred method is to stick a label on the thing you want to get back, like a branch:

git branch recover 705736f

此时,您可以签出它(这是一个新的本地分支),并确保已恢复所需的内容:

At this point you can check it out (it's a new local branch) and make sure you've recovered what you wanted:

git checkout recover
git log    # or gitk, or whatever

这是一个新的分支标签,指向旧的(rebase-attempt尝试)提交.

This is a new branch label, pointing at the old (pre-rebase-attempt) commits.

您的新提交(Decorator demo added)将在另一个分支上(在图形日志查看器中,例如gitk --branchesgit log,带有--graph)在Early version of the decorators demo提交之后派生.

Your new commit (Decorator demo added) will be on the other branch, which (in a graph log viewer, like gitk --branches or git log with --graph) forks off after the Early version of the decorators demo commit.

如果您愿意丢失"(在reflog中除外)新提交,则可以在reflog中将当前分支强制重置为旧提交:

If you're willing to "lose" (except for in the reflog) the new commit, you can force-reset your current branch back to the old commit in the reflog:

git reset --hard 705736f

(而不是创建指向705736f的新分支).再次,运行git log以查看是否要在该位置(甚至可以先git log 705736f!).

(instead of creating a new branch to point to 705736f). Again, run git log to see if that's where you want (you can even git log 705736f first!).

这篇关于git rebase吃了我的提交!翻译"git reflog"输出给我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆