Sam Weisenthal
Sam Weisenthal

Reputation: 2951

Losing more recent commits when checking out old commit

If

git log

#o/p

#commit 1

#commit 0

Then

git checkout 0

Then

git log

#commit 0

Commit 1 was erased...

I don't think this is normal behavior from my (limited) experience with git. I am using it in dropBox, but it seems that that's ok. Would really appreciate some help.

Upvotes: 0

Views: 173

Answers (2)

Sajib Khan
Sajib Khan

Reputation: 24174

When we checkout to a commit-hash we are no longer on a branch (detached HEAD).

Checkout to branch. You should be back to your branch HEAD (exits commit0, commit1)

$ git branch                 # copy your branch name
$ git checkout <branch-name> # back to branch HEAD

Or,
$ git checkout -             # switch to the last commit you were

Upvotes: 1

mshrbkv
mshrbkv

Reputation: 309

Commit 1 wasn't erased in this case. You just switched to an older commit and now git log shows only commits that are ancestors to that [older] commit.

You can use git checkout - or git checkout $commit1_hash to return to a newer revision.

Also, it may be helpful to use git reflog to see history of switches between revisions.

Upvotes: 1

Related Questions