git “致命:错误修订”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14550802/
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
What does "fatal: bad revision" mean?
提问by Rose Perrone
In the context:
在上下文中:
git revert HEAD~2 myFile
fatal: bad revision '/Users/rose/gitTest/myFile'
I'm sure HEAD~2 exists.
我确定 HEAD~2 存在。
EDITAmber is correct. I meant to use reset
instead of revert
.
编辑琥珀是正确的。我的意思是使用reset
而不是revert
.
回答by Amber
If you only want to revert a single file to its state in a given commit, you actually want to use the checkout
command:
如果您只想将单个文件恢复到给定提交中的状态,您实际上想使用以下checkout
命令:
git checkout HEAD~2 myFile
The revert
command is used for reverting entire commits (and it doesn't revert you tothat commit; it actually just reverts the changes madeby that commit - if you have another commit after the one you specify, the later commit won't be reverted).
该revert
命令用于还原整个提交(它不会将您还原到该提交;它实际上只是还原该提交所做的更改- 如果您在指定的提交之后有另一个提交,则不会还原后面的提交)。
回答by BenR
I was getting this error in IntelliJ, and none of these answers helped me. So here's how I solved it.
我在 IntelliJ 中遇到了这个错误,这些答案都没有帮助我。所以这就是我解决它的方法。
Somehow one of my sub-modules added a .git
directory. All git functionality returned after I deleted it.
不知何故,我的一个子模块添加了一个.git
目录。删除它后,所有 git 功能都返回了。
回答by Carl Norum
git revert
doesn't take a filename parameter. Do you want git checkout
?
git revert
不接受文件名参数。你要git checkout
吗?
回答by Nicolas Zozol
I had a "fatal : bad revision" with Idea / Webstorm because I had a git directory inside another, without using properly submodules or subtrees.
我对 Idea / Webstorm 有一个“致命的:错误的修订”,因为我在另一个目录中有一个 git 目录,没有正确使用子模块或子树。
I checked for .git
dirs with :
我检查了.git
目录:
find ./ -name '.git' -print
回答by AD7six
Git revert only accepts commits
Git revert 只接受提交
From the docs:
从文档:
Given one or more existing commits, revert the changes that the related patches introduce ...
给定一个或多个现有提交,还原相关补丁引入的更改......
myFile
is intepretted as a commit - because git revert
doesn't accept file paths; only commits
myFile
被解释为提交 - 因为git revert
不接受文件路径;只提交
Change one file to match a previous commit
更改一个文件以匹配先前的提交
To change one file to match a previous commit - use git checkout
要更改一个文件以匹配先前的提交 - 使用 git checkout
git checkout HEAD~2 myFile
回答by Suneel
I had a similar issue with Intellij. The issue was that someone added the file that I am trying to compare in Intellij to .gitignore, without actually deleting the file from Git.
我在 Intellij 上遇到了类似的问题。问题是有人添加了我试图在 Intellij 中与 .gitignore 进行比较的文件,而实际上并未从 Git 中删除该文件。
回答by Gregor
in my case I had an inconsistent state where the file in question (with the bad commit hash) was not actually added to Git, this clashed somehow with IntelliJ's state. Manually adding the file using git on the command line fixed the issue for me.
在我的情况下,我有一个不一致的状态,其中有问题的文件(带有错误的提交哈希)实际上没有添加到 Git 中,这与 IntelliJ 的状态在某种程度上发生了冲突。在命令行上使用 git 手动添加文件为我解决了这个问题。
回答by mrutyunjay
If you want to delete any commit then you might need to use git rebase command
如果要删除任何提交,则可能需要使用 git rebase 命令
git rebase -i HEAD~2
git rebase -i HEAD~2
it will show you last 2 commit messages, if you delete the commit message and save that file deleted commit will automatically disappear...
它将显示最后 2 条提交消息,如果您删除提交消息并保存该文件,删除的提交将自动消失...
回答by manojlds
Why are you specifying myFile
there?
你为什么要在myFile
那里指定?
Git revert reverts the commit(s) that you specify.
Git revert 还原您指定的提交。
git revert HEAD~2
reverts the HEAD~2
commit
恢复HEAD~2
提交
git revert HEAD~2 myfile
reverts HEAD~2
AND myFile
恢复HEAD~2
ANDmyFile
I take myFile
is a file that you want to revert? In that case use
我取的myFile
是您要还原的文件吗?在这种情况下使用
git checkout HEAD~2 -- myFile
git checkout HEAD~2 -- myFile