Engkus Kusnadi
Engkus Kusnadi

Reputation: 2506

Cancel back to previous commit

I learn git and I confused with this little problem. Here's the storyline

  1. I have 3 commits
  2. Now the status of my project files is modified (not staging)
  3. I accidentaly back to previous commit (commit 2), and my modified project files is overwritten by the previous commit

How I back to point 2 ? And how to prevent the same accident in the future?

Upvotes: 0

Views: 45

Answers (2)

Sajib Khan
Sajib Khan

Reputation: 24194

By giving git checkout <branch-name> you would be go top commit of that branch.

$ git checkout <branch-name>

Or, you can see all working tree history by git reflog command

$ git reflog                       # copy the commit-hash you want to go
$ git checkout <copy-commmit-hash> # go to a specific commit
$ git checkout -b <branch-name>    # create a new branch from that commit

Upvotes: 0

Martin G
Martin G

Reputation: 18129

You can git reset your branch back to whatever commit you want it to point to. If you don't know what commit this is, find out using git reflog to list the ones you have had checked out before.

Upvotes: 1

Related Questions