0

I'm currently learning git, and I have issue what exactly do these commands do?

git reset --hard HEAD~1

git checkout .

What's the difference between the two? They both permanently delete the last commit, as I understand. I think that there is a deep difference, so I hope for a clear explanation because I'm a beginner.

1

1 Answer 1

1
git reset --hard HEAD~1

makes your current branch/HEAD move to the previous commit.
--hard discards changes to tracked files, including staged changes.
(As this operation moves HEAD, an entry in git reflog is created)

git checkout .

discards unstaged changes from tracked files in the current directory tree.
This means: Staged changes will be kept on top of current commit!
To also discard staged changes you have to specify the commit to check out, e.g. HEAD: git checkout HEAD . - which will behave similar to git reset --hard HEAD (no ~1!) - if run in top directory of the repo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.