Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moved to different branch, lost changes - is there a way back?

I was working in the master branch and didn't realize it. I have hours of work that I did in that branch.

When I had finished what I wanted to commit, I went to GitHub Desktop v2.2.3 and noticed that I was in master. Before I had added them to staging, I listed the available branches and picked the one I wanted; it asked me what I wanted to do with the current changes, and I chose an option that said I wanted to "bring them with me".

Now I can't find my changes in either branch.

I went to the command line and entered "git reflog" and get the following:

e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{0}: checkout: moving from branchNumberOne to master
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{1}: checkout: moving from master to branchNumberOne
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{2}: reset: moving to HEAD
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{3}: clone: from https://gitlab.myURL.com/aCompany/myProject.git

I'm not even sure which HEAD index to use to try to get my changes back; how do I figure that out? Or is there another way to recover the changes?

like image 644
arcy Avatar asked Dec 08 '19 16:12

arcy


People also ask

Do you lose changes if you switch branches?

Switching branches does not require a clean index and working tree (i.e. no differences compared to HEAD ). The operation is aborted however if the operation leads to loss of local changes, unless told otherwise with --discard-changes or --merge .

How do you get uncommitted changes back?

The "restore" command helps to unstage or even discard uncommitted local changes. On the one hand, the command can be used to undo the effects of git add and unstage changes you have previously added to the Staging Area.

Can you recover a deleted branch git?

A deleted Git branch can be restored at any time, regardless of when it was deleted. Open your repo on the web and select the Branches view. Search for the exact branch name using the Search all branches box in the upper right. Click the link to Search for exact match in deleted branches.


Video Answer


1 Answers

Last time that happened to me IntelliJ saved my day, if you use any IDE you can undo changes on files you lost. Either by doing "undo" or using file history feature.

like image 111
Oskar Avatar answered Oct 18 '22 19:10

Oskar