git reset 中的歧义参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12900185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:38:13  来源:igfitidea点击:

Ambiguous argument in git reset

gitversion-control

提问by morfys

I recently screwed up a git rebase -i, and so I wanted to do a git reset --hard HEAD@{5}.

我最近搞砸了一个git rebase -i,所以我想做一个git reset --hard HEAD@{5}.

However, doing a git reset --hard HEAD@{5}or git log HEAD@{5}caused the following error message to be shown:

但是,执行git reset --hard HEAD@{5}git log HEAD@{5}导致显示以下错误消息:

fatal: ambiguous argument 'HEAD@{5}': unknown revision or path not in the working tree.

Then, I decided to specify the hash key corresponding to HEAD@{5}shown in git refloginstead. For instance:

然后,我决定指定对应于HEAD@{5}显示的哈希键git reflog。例如:

git reset --hard e8be841

In doing so, was there any risk screwing up the git repository or doing something unexpected?

在这样做时,是否有搞砸 git 存储库或做一些意想不到的事情的风险?

采纳答案by Adam Dymitruk

Git is very forgiving in how it does merges and rebases. If you look at the git repository's file structure during one of those operations, you will see that it alters files designated to help with those operations and does not unsafely change core objects. If it does, it's in an additive manner.

Git 在合并和变基方面非常宽容。如果您在这些操作之一期间查看 git 存储库的文件结构,您将看到它更改了指定用于帮助这些操作的文件,并且不会不安全地更改核心对象。如果是这样,它是一种相加的方式。

So there is practically no chance of doing any damage to your repository. As an example, take another repo, make a copy, start a rebase and then compare the .git folders in both.

因此,几乎不可能对您的存储库造成任何损坏。举个例子,拿另一个 repo,制作一个副本,启动一个 rebase,然后比较两者中的 .git 文件夹。

P.S. as per the comment on your question, yes, do use git rebase --abort

PS根据对您的问题的评论,是的,请使用 git rebase --abort

回答by Ena

For me the problem was I needed to put the double quotes on Windows command prompt.

对我来说,问题是我需要将双引号放在Windows 命令提示符上

Instead of:

代替:

git reset --soft 'HEAD^' 

I had to write:

我不得不写:

git reset --soft "HEAD^"

回答by Kenney

Git has some shell argument quoting issues.

Git 有一些 shell 参数引用问题。

Try git log 'HEAD@{5}'instead.

试试吧git log 'HEAD@{5}'

In my case I get the error fatal: Log .git/logs/HEAD is empty..

在我的情况下,我收到错误fatal: Log .git/logs/HEAD is empty.

The next workaround for this is:

下一个解决方法是:

git log HEAD^^^^^.

git log HEAD^^^^^.