git reset --mixed FETCH_HEAD

1.2k views Asked by At

Say I have a repo called repo1

Within this repo i have 5 revisions, with A being the most recent

A B C D E

Say I have a workspace with files at revision B but for some reason git thinks I'm at revision C.

I am interested in pulling down the git metadata so that my workspace is in the correct state(e.g git thinks i have revision B) but I do not want the files

My first idea was to run :

1) git pull -n

2) git reset --mixed B

However , this would fail due to merge conflicts

My second idea is to run :

1) git fetch -n

2) git reset --mixed FETCH_HEAD

3) git reset --mixed revision B

Is this the best solution ?

Thanks for your help.

1

There are 1 answers

0
Amber On

--mixed is the default action for reset, so you can omit that flag.

If you know your files are at revision B and revision B is already present in the repo, you can just reset direct to that SHA, no fetching needed:

git reset <sha>

If the commit isn't in the repo (e.g. you manually copied the files over), then you can fetch and reset to it:

git fetch <repo-with-b>
git reset <sha>

That will leave your actual files as they are, but tell Git that your repository is on the revision specified by <sha>.