I'm working on a class project, and when I went to do a push of all afternoon work I found this...
I googled "fatal: You are not currently on a branch" and found this...
Line by line I have followed the steps without fully understanding what I was doing, and when I finish I find that when I do a "git log", the most recent commit I see is from 13h (12h ago, more or less).
When doing Git Status I see this...
It looks like I've crashed all of today's work...is there a way to get it back?
Thanks.
In git it is difficult to lose changes that have been committed. When one commits some things happen:
As far as I know, the only way to lose a commit forever is to make sure no branches reference it, and run
git prune
.Safer than not, your changes are still on your computer. You can search for them using
git reflog
.This is an example of the output of
git reflog
: Find the last commit you created, and would like to return to, and copy its SHA. Once you find the commit that contains your valuable work, you can reset master to point to that commit.If all went well, when you run
git log
, it should show you that the tagmaster
points to the commit you wanted.You can return in several ways, some more dangerous than others, for example:
1.-You can return with:
this is also a way to create branches and move between them.
2.-with git reset you not only return but also delete the changes that were made after this commit, It is used in two ways:
git reset -hard borra
all the information in the staing area.You should also know that the git reset command is a dangerous command and should not be used without one of its flags (--soft,--hard,--HEAD). Once used there is no going back. git checkout is like a time machine that lets us go, look, wander, come back.
Official documentation:
git checkout
git reset