“致命的: 糟糕的修订”是什么意思?

在上下文中:

git revert HEAD~2 myFile
fatal: bad revision '/Users/rose/gitTest/myFile'

我肯定 HEAD ~ 2存在。

琥珀是正确的。我想用 reset代替 revert

148586 次浏览

If you only want to revert a single file to its state in a given commit, you actually want to use the checkout command:

git checkout HEAD~2 myFile

The revert command is used for reverting entire commits (and it doesn't revert you to that commit; it actually just reverts the changes made by that commit - if you have another commit after the one you specify, the later commit won't be reverted).

git revert doesn't take a filename parameter. Do you want git checkout?

Why are you specifying myFile there?

Git revert reverts the commit(s) that you specify.

git revert HEAD~2

reverts the HEAD~2 commit

git revert HEAD~2 myfile

reverts HEAD~2 AND myFile

I take myFile is a file that you want to revert? In that case use

git checkout HEAD~2 -- myFile

Git revert only accepts commits

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

Change one file to match a previous commit

To change one file to match a previous commit - use git checkout

git checkout HEAD~2 myFile

If you want to delete any commit then you might need to use git rebase command

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...

I was getting this error in IntelliJ, and none of these answers helped me. So here's how I solved it.

Somehow one of my sub-modules added a .git directory. All git functionality returned after I deleted it.

I had a "fatal : bad revision" with Idea / Webstorm because I had a git directory inside another, without using properly submodules or subtrees.

I checked for .git dirs with :

find ./ -name '.git' -print

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.

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.

I tried all of this, and git was complaining that the pathspec of the file I was trying to checkout was unknown.

The easiest fix for me was to delete the already versioned file locally and revert to the versioned version.

For me, I was in the wrong directory and did not even notice