
If you have a different remote and default branch name (not origin or main, respectively), just replace them with the appropriate name. All changes in the working area and staging area will stay intact. You can back it up like so: git commit -a -m 'Branch backup' git branch branch-backup Now run the command below to reset your remote branch to origin. It will just move the HEAD explicitly to the commit. When we perform a soft reset the commit snapshot is not copied to the staging area or to the working area. In our example, the position of the HEAD pointer upon a mixed reset will be as shown in the below diagram. The syntax to perform a hard reset using the HEAD pointer will be − git reset -mixed HEAD~įor example, the following command will move the HEAD 2 commits backwards. Let’s have a look at the changes using the git status command. git reset -soft HEAD (or HEAD1) This time, the staging area will be filled with the changes done between commit 7a9ad7f and commit 802a2ab.

So, the current changes in the working area will stay intact. In order to move the HEAD to one commit before, use the git reset command with the soft option and specify HEAD. Mixed reset copies the snapshot from the repository to the staging area only. This is the default option for resetting. Since the commit is now pointing at c1, the other commits c2 and C3 will be garbage collected. The following diagram shows the position of the HEAD pointer after executing the above command. Where, i is the number of commits to move backwardsįor example, the following command will move the HEAD 2 commits backwards. The syntax to perform a hard reset using the HEAD pointer will be- git reset -hard HEAD~ Due to this any changes done in the current working directory or staging area prior to performing the hard reset will be lost. HEAD points to your current branch (or current commit), so all that git reset -hard HEAD will do is to throw away any uncommitted changes you have. When performing a hard reset, git will copy the commit snapshot into the working area as well as the staging area.

If you do not need to edit the message further, you can give. When resetting the HEAD pointer, we have 3 options − git/ORIGHEAD redo the commit by starting with its log message. The git reset command will explicitly or forcibly move the HEAD of the branch to a specific commit. We can perform a reset using the HEAD pointer or commit hash. After each commit operation the HEAD pointer moves ahead to the new commit. Delete the commit git reset -hard HEAD HEAD is now at 326fc9f append description of. The below diagram shows that initially HEAD was pointing to commit c1. Use the reset command to delete the previous two commits like below. The commit command moves the HEAD of a branch implicitly.
