A
A
Anton Mikhailov2022-03-19 15:59:38
git
Anton Mikhailov, 2022-03-19 15:59:38

How to see the previous commit without deleting the current one?

Hello!
Created commit One, made changes, created commit Two.
git log shows two commits ( One and Two)

Task: I want to see the status of the project on commit One and then return to commit Two (current, last)
1. I type the command git checkout + commit hash One
2. I see changes in the html file as was at the beginning (commit One), i.e. everything OK - I looked, I'm satisfied-)
3. I run git log - I see only one commit number One.

Q:
Why was commit Two removed?
How to look at the past states of the project and then return to the current state of the project (last commit)?

Thanks).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2022-03-19
@fAntonM

He didn't leave. Read the Git Book to understand what each command does
. You have moved the HEAD pointer to a specific commit. Now go ahead git checkout master(if the master branch is master, which is most likely) and watch both commits.

A
Anton Mikhailov, 2022-03-21
@fAntonM

Colleagues, tell me more.
I noticed that if I try to roll back to the previous commit by the SHA-1
git checkout 09164b82059dbadcd75d82994e94d13eb63e210e1 ~
I get an error (the tilde character at the end he added)
git checkout 09164b82059dbadcd75d82994e94d13eb63e210e1 ~
error: pathspec '09164b82059dbadcd75d82994e94d13eb63e210e1 ~' DID not the match the any file (s) known to the git

BUT, if through git hist
git checkout e3ff6c0
then everything works
Question: does this mean that it is impossible to switch to a commit through SHA-1.
What other simple commands are there to switch to the desired commit?
Thanks).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question