I made a commit, pulled and merged some changes, and then made a second commit. When I wanted to go back to the first commit, I ran the command
git reset --hard <sha hash>
While the response was "HEAD is now at <sha hash>", my code looks just as it did before I ran that command. Usually, it changes to what I had before, but it looks like something isn't working correctly. Do I need to run a different command to unmerge before resetting head?
When I run git status
it says:
app/assets/images/.DS_Store.orig is untracked
and I can add it.
According to git reflog
, I pulled before I made the commit hash1 (which I consider "before merge"). There is an sha hash2 for the pull (which git log
did not show). When I dig hash1 and hash2, I see the changes I made and could reconstruct my original code from this. Still, this seems very strange. If I try to git reset
to either of them, I cannot get my code from before the merge.
The:
git reset --hard <sha-hash>
won't work when:
.gitattributes
),Maybe the solution would be to go back what you have on remote branch by:
git reset origin/master --hard
and rebase
hash on top of it or git cherry-pick
the commits which you really need.
If above doesn't help, you should also:
git branch -a
), not on detached one,git reflog
for more details about your history,git blame some/file
to show at what revision your line of code was modified, this helps you to track the problem at which commit your code looks like you would not expect,revert
it.