I’m using git through Eclipse. I created a new file, as well as making changes to an existing versioned file. I committed and tried to pull changes, but ran into a conflict with the existing versioned file. I was unable to resolve it, so I finally hard reset back to before my commit. This fixed the conflict, but also deleted the new, unversioned file I had created. Is there any way to get that file back? I didn’t think the hard reset would affect the unversioned file.
Share
git reset --hardwon’t affect unversioned files, but once you added the new file to the index and committed it wasn’t unversioned anymore, so resetting to a commit that didn’t have that file will lose it. You can get it back by resetting to the commit that added that file. Rungit reflog; you’ll get output along these lines:HEAD@{1}was your new commit;HEAD@{0}was resetting back to the old one. Reset again, to the commit before the reset that lost the new file (in my example, it’sHEAD@{1}):This restores the repository to the state it was after you committed, before you reset, so the new file should be back. As to what you were trying to do originally, there are a few ways to reset without losing the new file you added in your latest commit. The easiest way is probably to do a mixed reset, and then a checkout:
The mixed reset will leave the repository the way it was before you committed — you’ll have uncommitted changes to the old file, and the new file will be unversioned. The checkout will revert your changes to the old file, but since the new file is unversioned now it will leave it alone