| by Arround The Web | No comments

How can I Revert Uncommitted Changes Including Files and Folders?

Developers perform operations on the local directory and then push those local changes to the Git staging area for tracking purposes. They update their files and folders periodically according to their requirements. Sometimes, they may create new files or update the existing ones and add changes to the staging area. However, later it is realized that those files are not needed anymore. In such a situation, revert those uncommitted changes.

This blog will explain the procedure of reverting the uncommitted changes including all files.

How to Revert All Uncommitted Changes Including Files and Folders?

To revert the uncommitted changes, including files and folders, follow the below-provided instructions:

  • Switch to the local repository.
  • Generate new files.
  • Add files to the staging area.
  • Check Git status.
  • Revert uncommitted changes
  • Verify changes.

Step 1: Navigate to Local Directory

First, redirect to the local Git directory by running the following command:

cd "C:\Git\ReposB"

Step 2: Create New Files

Next, utilize the “touch” command along with the files name to create new files in the repository:

$ touch FileA.txt FileB.txt

Step 3: Add files to Git Index

Then, add the newly created files to the Git staging area using the below-provided command:

$ git add .

Step 4: Check Git Status

Now, check the current status of the current working repository:

$ git status

It can be observed that newly created files have been added to the staging index and need to be committed:

Step 5: Revert Uncommitted Changes

Write out the “git reset” command along with the “–hard” option to revert the uncommitted changes:

$ git reset --hard HEAD

As you can see, the revert operation has been performed:

Step 6: Verify Changes

At last, check the Git status to see if there are uncommitted changes or not:

$ git status

According to the below-provided screenshot, the Git status is clear now, and the uncommitted changes have been reverted successfully:

We have efficiently demonstrated the process of reverting uncommitted changes, including files and folders.

Conclusion

To revert the uncommitted changes, first, redirect to the desired local directory. Then, check the current status of the working directory to see the uncommitted changes. Then, run the “git reset –hard HEAD” command to revert the uncommitted changes, including files and folders. Lastly, check the Git status again to verify the changes. This blog explained the method to revert the uncommitted changes.

Share Button

Source: linuxhint.com

Leave a Reply