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
.
The error message "bad revision" indicates that the local repository in your build doesn't contain one of the commits you're referencing. This happens because Pipelines does a shallow clone by default, containing just the most recent 50 commits on the current branch.
The revert command You can find the name of the commit you want to revert using git log . The first commit that's described there is the last commit created. Then you can copy from there the alphanumerical name and use that in the revert command.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With