INTRODUCTION
GIT reset performs a rollback by adjusting the current working directory or repository to point to a previously specified commit. This will discard the commit/push related changes done in the current working repository and reset the HEAD reference to a specified previous commit, discarding all commits made after that point.
Note that the term Github HEAD refers to the currently checked-out branch's latest commit.
MODES OF GIT RESET
The GIT reset functionality has three options for the invocation of the reset command: SOFT RESET, MIXED RESET and HARD RESET.
SOFT RESET
The Soft Reset option will reset the HEAD to the specified commit and save the changes in the index (staging area) without any modifications in the working directory. The implementation of Soft Reset option after performing the commit and push operation will move the test suite files and other dependencies back to the staging area in DevOps Test UI. The status of the test suite files after Soft Reset will be set to “ready to commit”.
MIXED RESET
The Mixed Reset option moves the HEAD to the specified commit and resets the index (staging area) without any modifications in the working directory. The implementation of Mixed Reset option after performing the commit and push operations will reset the staging Index to match the state of the specific commit.
HARD RESET
The Hard Reset option moves the HEAD to the specified commit and resets both the index (staging area) and the actual working directory. The Hard Reset option discards all the previous changes permanently from both the index and the working directory. The implementation of Hard Reset option after performing the commit and push operation will reset the staging index and the working directory to match the state of the specific commit.
(Note: Since the usage of the Hard Reset option discards all the changes permanently from the index and the working directory, it is recommended to make a backup copy of the test suite files from DevOps Test UI before using this option).
How to implement SOFT RESET, MIXED RESET and HARD RESET from DevOps Test UI
The implementation of SOFT, MIXED and HARD reset from DevOps Test UI can be achieved as follows:
- Launch DevOps Test UI, create a Test UI project and a Web UI test.
- Connect the Web UI test project to the GitHub remote repository.
- Perform the commit and push operation to push the entire Test UI project to the remote repository from the Test UI Git perspective. The project is present in the remote repository now.
- Modify a test step in the Test UI script in DevOps Test UI and save the test script.
Test step before modification:
Test step after modification – note that the Think time has been changed to 2000 milliseconds.
- Switch to the Git perspective and navigate to the Git Staging view.
- Click on Add to index option to move the test suite file from the Unstaged Changes section to the Staged Changes section.
Unstaged Changes section:
Staged Changes section:
- Add a message in the Commit Message section and click on Commit and Push button to push the test suite file to the remote repository.
- The following pop-up window appears after the successful commit and push operation.
- Navigate to the remote repository in Github and verify if the test is successfully pushed to the remote repository.
- Navigate to the Git Reflog view from the Git Staging view.
- Choose a previous commit on Git Reflog view to revert to. For example, in the following screenshot select the commit with message as Script Modified.
Now let’s see how the different Git reset options are implemented.
---------------------------------------------------------IMPLEMENTATION OF SOFT RESET-------------------------------------------------------------------------
- Right-click on the selected commit and navigate to the Reset -> Soft (HEAD Only) option.
- Click on Soft (HEAD Only) option to perform the soft reset.
- The HEAD will be reset to the previous specific commit containing Commit Message as Script modified.
- Navigate to the Git Staging view and observe the test suite file is moved back to the Staged Changes section.
--------------------------------------------------------IMPLEMENTATION OF MIXED RESET----------------------------------------------------------------------
- Navigate back to the Git Reflog view and select the specific commit to perform Mixed reset. Select the same commit with Commit Message as Script modified to perform the Mixed reset.
- Click on the Reset -> Mixed (HEAD and Index) option to perform Mixed Reset.
- Navigate to the Git Staging view and observe that the test suite file is now moved to the Unstaged Changes section from Staged Changes section.
--------------------------------------------------IMPLEMENTATION OF HARD RESET---------------------------------------------------------------------------
- Navigate back to the Git Reflog view and select the specific commit to perform Hard reset. Select the same commit with Commit Message as Script modified to perform the Hard reset operation.
- Click on the Reset -> Hard (HEAD, Index, and Working Tree) option to perform Hard Reset operation.
- Click the Reset button from the Confirm Reset dialog box appears to discard the previous commits from the working tree.
- Click on the Yes button to load the modified file changes in the test script.
- The Hard reset will reset the HEAD and modify both the working directory and Index to the specified commit state. Open the Web UI test and observe that the test step Click on Edit text shows the think time as 0 instead of 2000 milliseconds, which means that the script is reverted to the specific commit state.
- Navigate back to the Git Staging view and click on the Push HEAD button to push the script to the remote repository.
- The Push operation is performed to push the current status of HEAD after reset to the remote repository.
Remote repository before the push operation.
- A pop-up appears after the successful push operation to the remote repository.
- Here is the remote repository after the push operation of HEAD with the specific commit.
Cl
SUMMARY
Here is the summary of how to use the SOFT RESET , MIXED RESET and HARD RESET options:
SOFT RESET:
This implementation of the soft reset option is helpful for the following scenarios:
- If you prefer to amend a commit or rebase your branch, keeping the test script modifications under staged changes. Soft reset can move the HEAD to a specified commit while keeping the current changes staged.
- If you want to undo the commit and keep the test script changes in the working directory and staging area for further modifications or re-committing.
- If the commit operation is done by mistake and you want to combine it with the previous commits. A soft reset can help with the rework of these commits while preserving the test script changes in the working directory.
- If you want to modify the commit message without altering the commit contents(test suite files).
·
MIXED RESET:
This implementation of the mixed reset option is helpful for the following scenarios:
- If you want to adjust and decide about the test script changes to be staged for the next commit without losing your uncommitted work. If you want to reset your branch to a previous state and prepare for a new commit, a mixed reset can be used to move the HEAD and unstage changes, making it easier to start fresh from a specific point in your commit history.
- If you want to exclude staged changes in the next commit and keep the test script modifications in the working directory, then you can use mixed reset to unstage them. This is useful for a scenario when the test suite files are added by mistake to the staging area.
- If you prefer the committed changes to be staged differently, a mixed reset can move the HEAD to an earlier specified commit and unstage the test script changes that were included in later commits. This will be helpful to re-stage and commit changes as per the requirement.
Note: The mixed reset will not affect your working directory files, but it will change the staging area, so it is recommended to use this option correctly to avoid losing changes.
·
HARD RESET:
This implementation of the hard reset option is helpful for the following scenarios:
- If you have made changes to your working directory and staging area that is no longer required and you want to discard the changes from your local repository (Workspace in DevOps Test UI). A hard reset can revert your repository to a specific commit, discarding all uncommitted changes. The working directory and staging area will match the specified commit after executing Hard reset option.
- If you want to undo a series of commits or changes entirely and return to a clean state then a hard reset can help you revert to a previous commit. This option is useful if you need to undo multiple commits or fix a mistake that impacts the entire repository state.
- If you have pushed unwanted commits to the remote repository which is required to be removed now, then you can use hard reset to reset the branch and then force-push the changes.
Note: It is recommended to carefully work with the Hard reset and force-push options as force-pushing can overwrite changes on the remote repository, affecting others who might be working with that branch.
·