Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accidentally stopped command in middle of git checkout how do I recover

Tags:

git

I ran git checkout and stopped the process in the middle. Now I can't switch branches because it complains I'll overwrite local files. How do I get around this? eg

git checkout egotailer error: Your local changes to the following files would be overwritten by checkout: ...

I tried

git clean -d -x -f

but it didn't help

like image 558
John Montague Avatar asked Oct 26 '25 15:10

John Montague


2 Answers

well, if you know that your repository is all up to date and that you have nothing outstanding to be checked in, simply reset your branch back to the HEAD.

git reset --hard HEAD
like image 128
Tim Jarvis Avatar answered Oct 29 '25 04:10

Tim Jarvis


git reset --hard

should do it. HEAD is implied when you don't specify a reference.

WARNING This is the most common way to lose work in Git!!

A safer way to clean your directory is

git stash -u

or

git stash --include-untracked

This will do what git reset --hard does but you can't accidentally lose information. It is only available as of version 1.7.7. Before that you had to

git add -A && git stash

for the same effect.

Later, if you realize you are missing important work, you can get it back from the stash.

like image 30
Adam Dymitruk Avatar answered Oct 29 '25 04:10

Adam Dymitruk