Git: How to reset hard to refspec
Im doing some work with gerrit, and with gerrit you only get the refspec of a commit. Something like:
refs/changes/01/15501/2
How do I reset hard to this?
I tried to play nice
[me@server code ((7deac0e...))]$ git reset --hard refs/changes/01/15501/2
fatal: ambiguous argument 'refs/changes/01/15501/2': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
This was not the best error message, so I tried agian...
[me@server code ((7deac0e...))]$ git reset --hard -- refs/changes/01/15501/2
fatal: Cannot do hard reset with paths.
I dont need to use reset --hard, but it would work well in my situation. My script runs in the code repo, but I have no idea what state it is in. There is only one开发者_开发百科 file which is reliable and doesn't change, which is the reset_to_gerrit script.
I tell that script to reset to some refspec, and that puts my code repo in a place that i atleast know what to expect. There is a very high possibility of merge conflicts between the original and final state, and reset hard should avoid all of that.
You can do it in two steps.
- First fetch the change
- Then hard reset to FETCH_HEAD
Something like:
git fetch origin refs/changes/01/15501/2
git reset --hard FETCH_HEAD
精彩评论