Git is a decentralized model management system utilized amongst builders engaged on comparable initiatives as a crew. On this platform, the crew members could make modifications at any time and inform different members by committing modifications from the native repository to Git distant repository. Nonetheless, generally, one can mistakenly commit and need to take away it. In such a situation, Git permits its customers to revert a number of commits concurrently.
This research will talk about the process of reverting a number of commits in Git.
How you can Revert A number of Commits in Git?
To grasp the process of reverting a number of commits, first, transfer to the precise listing. Subsequent, create and add recordsdata to the Git listing. Then, revert a number of commits.
Now, go forward and carry out the required directions.
Step 1: Launch Git Bash
Search and launch the “Git Bash” terminal utilizing the “Startup” menu:
Step 2: Navigate to Git Listing
Transfer to the precise listing the place you need to revert a number of commits:
$ cd “C:CustomersnazmaGittestfirst_demo”
Step 3: Create New File
Subsequent, create a brand new file using the “contact” command:
The error-free output signifies that the brand new file “file3.txt” is created efficiently:
Step 4: Add File into Git Repo
Now, add the created untracked file to Git repository:
Step 5: Commit Adjustments
Subsequent, execute the “git commit” command with “-m” flag to commit all modifications:
$ git commit -m “file3 added”
Step 6: Create New File
Run the “contact” command to create a brand new file:
Step 7: Add File
Add the newly created file into the Git repo using supplied command:
Step 8: Commit Adjustments
Now, commit all modifications to Git repo with a message:
$ git commit -m “file4 added”
Step 9: Examine Log Historical past
To see the present place of HEAD, verify the log historical past using the “git log” command with the “–oneline” flag:
As you may see, we’ve multiple commit, and at present HEAD is referring to the latest commit:
Step 10: Revert A number of Commits
Execute the “git reset” command with “–laborious” choice to revert a number of commits collectively:
$ git reset –hard 1ec268c
Beneath output signifies that our HEAD is efficiently reverted to “1ec268c” commit ref which is our first commit “Create file1” and multiples commits are eliminated:
Step 11: Examine Log Historical past
Lastly, execute the “git log –oneline” command to confirm the carried out operation:
Right here, our “first_demo” listing incorporates only one commit remainder of the modifications are eliminated:
That’s it! We have now supplied the simplest technique to revert a number of commits in Git.
To revert a number of commits in Git, first, open the Git terminal, and navigate to the precise Git listing wherein you’re required to revert a number of modifications. Then, create and add recordsdata to the listing. After that, commit all modifications. Lastly, run the “$ git reset” command with the “–laborious” flag and the commit reference to revert them again. This research has elaborated on the process of reverting a number of commits in Git.