"Reset Current Branch to Here" on local untracked branch -- commit history lost?

已回答

I think I just did something horribly stupid. I have a local branch (not pushed to remote) and I went to the VC -> Logs tab, chose a commit several commits back, and chose "Reset Current Branch to Here" thinking I could jump back to where I was... but those commits no longer appear in the Logs tab or anywhere. I checked the Local History and it doesn't seem to show those commits either. I can revert in Local History to a point that has all the changes, but the commit history is still gone. Did IntelliJ really just erase those commits?

0

Reset Current Branch to Hear does exactly that - it drops all the commits above selected with git reset command. So it is expected that the commits are not shown in the Log anymore.

While there is no way of restoring commits via UI, you could go to the command line, execute git reflog and find the has of the commit which was the head before you reset the branch. then checkout the comit by hash - git checkout %hash% - and create a new branch from there.

See e.g. https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1

BTW, Local history tracks file changes, not commits, so it cannot be used to restore commits.

3
 

Thanks! You save my day

0

请先登录再写评论。