in Education by
How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get the following output: $ git log commit a867b4af366350be2e7c21b8de9cc6504678a61b` Author: Me Date: Thu Nov 4 18:59:41 2010 -0400 blah blah blah... commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4 Author: Me Date: Thu Nov 4 05:13:39 2010 -0400 more blah blah blah... commit 0766c053c0ea2035e90f504928f8df3c9363b8bd Author: Me Date: Thu Nov 4 00:55:06 2010 -0400 And yet more blah blah... commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50 Author: Me Date: Wed Nov 3 23:56:08 2010 -0400 Yep, more blah blah. How do you revert to the commit from November 3, i.e. commit 0d1d7fc? Select the correct answer from above options

1 Answer

0 votes
by
If you need to switch temporarily to a committed branch $git checkout commit id will be available in $git log and it should be the id of the commit that you need to revert.If you need to make commits, go ahead and make a new branch $ git checkout -b (ie ;- $git checkout -b master ). To go back, you just checkout the branch that you were on again. (If you've made changes, when switching branches, you'll have to deal with them as appropriate. You could reset to throw them away, you could commit them to a branch there if you want a branch there.) HARD DELETE FOR UNPUBLISHED COMMITS If you need to reset all mess that you have created during revert use $git reset --hard . Do only if you have committed the work that you need further. Also, you can stash, pop if there is a work to save This saves the modification, then re-applies that patch after resetting. If you already published the commits then you need to undo the published commits with new commits. Undoing published commits can be done by using revert command. $git revert you can give the reverted commits by giving ranges. $git revert HEAD~2...HEAD. Reverting a merge commit $git revert -m 1 You can get your index and work tree into the desired state, without changing HEAD $git checkout 0d1d7fc32 .(commit-id) then finally commit using $git commit, thus, you can undo published commits.

Related questions

0 votes
    I have made some changes to a file that has been committed a few times as part of a group of files, but ... former state in the past Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I would like to know how to delete a commit. By delete, I mean it is as if I didn't make that commit, ... -hard HEAD. Is this correct? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some ... my original project checkout. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How to revert a Git repository to a previous commit?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    I pulled a project from GitHub a few days ago. I've since discovered that there are several forks on GitHub, ... those forks I pulled? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    As asked in this question, I also want to know how to resolve a conflicting git stash pop without ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I started some work on a new feature and after coding for a bit, I decided this feature should be on its ... on the new feature. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Recently, I have been asked to cherry-pick a commit. So what does cherry-picking a commit in git mean? How do you do it? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I would prefer to write my commit messages in Vim, but it is opening them in Emacs. How do I configure Git ... for a single project. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How do I discard changes in my working copy that are not in the index? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I don't want to rename a remote branch, as described in the Rename master branch for both local and remote ... and remote branch name Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    In Git how do you revert a commit that has already been pushed and made public?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    I usually submit a list of commits for review. If I have the following commits: HEAD Commit3 Commit2 Commit1 ... ... the HEAD commit? Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
0 votes
    I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
...