Background: I have a local repository that has a remote. All has gone well for quite some time. I'm doing development on a Mac and using GitX. Before the problem I'm about to describe, I had pushed to the remote 5 days ago, and had 10 local commits since then that are unpushed.
Problem: I staged a commit in GitX, wrote its commit message, and pushed the keyboard shortcut key for "commit," just like I've done many times. (At least, so I think--I did it quickly, so perhaps I did something different by accident--not sure.) Then the following situation occurred:
git log
from the command line lists one entry only, the last commit I just made.git log -g
from the command line lists the full history, including the 10 missing commits, and the most recent one.I have no idea what's going on, or why any of the above 5 things are happening. I do not understand the difference between git log
and git log -g
(aka git log --walk-reflogs
) but it seems to be where the data I'm missing is residing.
Questions: How can I get back the 10 commits that only appear in git log -g
? How can I reattach the master to the rest of the history? What on earth caused this in the first place?
I do not know gitX, but it looks a lot like you created a commit with no parents by accident. If that’s the case, you need to follow these steps:
.git
repository in case something goes wrongSHA1
)git reflog master
and maybe gitk --walk-reflogs
or git log --walk-reflogs
to find the SHA of your previous commit (SHA2
).git checkout -B master **SHA2**
to get back to that commitgit checkout **SHA1** -- .
to get your changes back in the working directory