Okay so I made some changes in my project that resulted in a huge mess. I had already committed the changes so I could go back to it later, and then used git checkout HEAD^ to checkout the previous commit. Now as I’m making commits to my project it shows the SHA-1 on the command line as the working branch (instead of master)
I don’t know everything there is to know about git but I’m guessing HEAD is still pointing to my broken copy as I’m going off in a tangent and have resolved the problem. How can I point HEAD to the latest commit I’m working from?
I’m guessing it has to do with rebase but I’m not 100% sure.
Thanks.
Now as I’m making commits to my project it shows the SHA-1 on the command line as the working branch (instead of master)
This probably means you have a “detached HEAD”. A detached HEAD points directly to a commit instead of pointing to a branch (which then points to a commit). A detached head is like an unnamed branch.
This state was caused by your
git checkout HEAD^command asHEAD^refers to a commit, not to a branch name. You probably wanted to dogit reset --hard HEAD^—while master was still the active branch—to drop the most recent commit from master (it would still exist on disk and be reachable through the reflog until its entry in the reflog expired).How can I point HEAD to the latest commit I’m working from?
HEADis always the commit from which you are working, whether it is detached or not.If you mean “How can I point master to the latest commit I’m working from?”, then that is the same as asking “How can I get master to point to
HEAD?”. The answer is(actually, you can leave off
HEAD, since it is the default). This forcibly resets master to the commit currently atHEAD. Any commits on master that are not reachable via another branch or the currentHEADwill henceforth only be reachable via the reflog and will eventually be garbage collected (this throws away, from master, anything in master that is not inHEAD). You also probably want to reattach yourHEADto this updated master after this.Instead of the two commands above, you could reattach
HEADfirst, then reset master with these two consecutive commands:The
HEAD@{1}notation is used to access entries in the reflog. This example just means “the previousHEAD” (i.e. “the commit atHEADbefore the most recent operation that affectedHEAD”).