+15 votes
1 view
in DevOps and Agile by (30k points)

With git log, I get a list of commits that I have made so far.

commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1

Author: chandra

Date:   Fri Jul 5 14:36:59 2019 -0500

    Added and modified the files.

commit c14809fafb08b9e96ff2879999ba8c807d10fb07

Author: chandra 

Date:   Tue Jun 25 08:59:32 2019 -0500

    Just simple test for core.editor.

How can I revert it back to a specific commit? For example, what should I do if I want to go back to commit c14809fafb08b9e96ff2879999ba8c807d10fb07?

Is there any other/better way to go back to a specific commit with Git? For example, can I put some labels of each commit to get it back with the label?

1 Answer

+10 votes
by (63.4k points)

Do you want to roll back your repo to that state? Or you simply wish your local repo to look like that?

If you want your local repo to look like that use:

git reset --hard c14809fa

It will build your local code and local history be just like it had been at that commit. But then if you wanted to push this to some other person who has the new history, it'd fail.

if you do

git reset --soft c14809fa

It will move your HEAD to where they(the person has new commit) were, however leave your local files etc as the same. So what exactly do you want to do with this reset?

Edit -

You can add "tags" to your repo.. then return to a tag.

But a tag is really just a shortcut to the sha1.

You can tag this as TAG1.. then a git reset --soft c14809fa, git reset --soft TAG1, or git reset --soft c14809fafb08b9e96ff2879999ba8c807d10fb07 would all do the same thing.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...