2

I have committed a file and commit id (hash) is 1234. In the same file i do lot of changes and again commit a file so new hash is 567. I repeat the process so newly generated hash are like 8910,111213.

I want to go back the version 1234 (the same version i got at the time of first checkin)

What are the step for this?

James Z
  • 12,209
  • 10
  • 24
  • 44
MiniSu
  • 566
  • 1
  • 6
  • 22
  • 2
    Does this answer your question? [Go to particular revision](https://stackoverflow.com/questions/7539130/go-to-particular-revision) – FreshD Apr 13 '20 at 08:14

2 Answers2

1
# clone repo without initial checkout of HEAD
git clone -n <repo_name>

# checkout specific commit
git checkout 1234

--> see
https://coderwall.com/p/xyuoza/git-cloning-specific-commits
https://guide.freecodecamp.org/git/git-checkout/

  • commit hash 1234 belong to branch A so after aplying git checkout 1234 can i push it to branch A or i need to create new branch? – MiniSu Apr 13 '20 at 08:20
  • That depends if you want to keep the changes you've already made. `git reset --hard 1234` # resets your current branch to this commit (and deletes the future commits) to push the changes you need a `git push --force ...` if you want to keep the changes I would recommend to create a new branch after the checkout – Lukas Heiligenbrunner Apr 13 '20 at 12:26
0

You can checkout a commit hash and then create a branch from it if you want. You'll be interacting with the tree at that point in the history.

If you run git checkout <hash> you'll update the tree to that point in the history. Depending on the git client you're using you'll get a message like

> git checkout <hash>

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>

Joe W
  • 2,773
  • 15
  • 35