0

My git log was showing several project commits in my projects. I'm using only master branch. I have done git checkout to first commit. I was expecting that my directory will be changed to state when it was in during first commit. It not happened. How to achieve that?

Now git console shows that I'm in first commit by showing ((b266cf..)) instead of (master) in command prompt. And git log shows that there is only one commit - first one? Where others are gone? How to get back to state where all others commits are visible?

5
  • What are you trying to do here? You checked out some commit in the detached HEAD state, which may not be what you wanted to do. If you can clue us in about your desired goal maybe someone can help you. Commented Dec 24, 2016 at 10:05
  • how to get out from detached HEAD state? And I would like "git log" show all logs - not only first on like it is currently
    – vico
    Commented Dec 24, 2016 at 10:12
  • Just checkout the branch again, i.e. git checkout master ... but what were you trying to do? Commented Dec 24, 2016 at 10:13
  • "git checkout master" brings back (master) in command prompt, "but git log" still shows only first commit. Where are others?
    – vico
    Commented Dec 24, 2016 at 10:16
  • I don't know where the other commits are, but what you are seeing in master is what is actually there. Perhaps you can try doing git pull origin master to get any new commits coming from the repository? Commented Dec 24, 2016 at 10:18

1 Answer 1

0

git log shows that there is only one commit - first one?

That is expected: if you checkout the first commit, git log will show all commits accessible since that checked out commit. Since it is the first one, git log only shows this one.

"git checkout master" brings back (master) in command prompt, but "git log" still shows only first commit. Where are others?

If somehow master is not properly restored, check the output of git reflog.

Any commit you have done in that repo is listed in git reflog: you will be able to reset master to the commit you want.

git checkout master
git reset --hard <another_commit_sha1>

Or git branch -f master new-tip-commit (might not work if master is the currently checked out branch)

Not the answer you're looking for? Browse other questions tagged or ask your own question.