In the context:
git revert HEAD~2 myFile
fatal: bad revision '/Users/rose/gitTest/myFile'
I'm sure HEAD~2 exists.
EDIT Amber is correct. I meant to use reset
instead of revert
.
This question is related to
git
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 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
git revert
doesn't take a filename parameter. Do you want git checkout
?
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.
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
To change one file to match a previous commit - use git checkout
git checkout HEAD~2 myFile
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.
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
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.
Source: Stackoverflow.com