This schema illustrates which command does what.Īs you can see there reset & checkout modify the HEAD. # the can be any commit(s) or commit range # add new commit with the undo of the original one. The reset command will "undo" any changes made in the given commit.Ī new commit with the undo patch will be committed while the original commit will remain in the history as well. You can also use the git rebase -no-autostash as well. # You could get merge conflicts if you've modified things which were ![]() # This saves the modifications, then reapplies that patch after resetting. # Alternatively, if there's work to keep: # Don't do it if you have uncommitted work you want to keep. # This will destroy any local modifications. "Move" your HEAD back to the desired commit. Git checkout will get you back to your desired commit Git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.Įvery time the HEAD is modified there will be a new entry in the reflog git reflog # create a new branch forked to the given commit # in order to be able to update the code. # is not pointing to the latest so you will need to checkout branch # Doing so will result in a `detached HEAD` which mean that the `HEAD` This command will checkout to a given commit.Īt this point, you can create a branch and start to work from this point on. This will checkout new branch pointing to the desired commit. The easiest way to undo the last Git commit is to execute the git reset command with one of the below options. Git checkout HEAD~X // x is the number of commits t go back On the command line, it will look like this- SHA-1 instead of the branch name since the HEAD is not pointing to the tip of the current branchĪ few options on how to recover from a detached HEAD: If you are not on the latest commit - meaning that HEAD is pointing to a prior commit in history its called detached HEAD. git/HEAD and it contains the 40 bytes SHA-1 of the current commit. There can only be a single HEAD at any given time. HEAD is simply a reference to the current commit (latest) on the current branch. Simply checkout any SHA-1 that you wish to revert toīefore answering let's add some background, explaining what is this HEAD. ![]() Type it in your console and you will get a list of your git history along with SHA-1 representing them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |