Git

Git: Undo All Working Dir Changes Including New Files

Git is the most popular project-tracking tool that helps developers manage large projects. They can generate new files, directories, branches, tags, and many more operations. They can also undo all working directory changes including new files. To perform a previously discussed operation, the “git clean -f -d” command can be used.

This guide will discuss the process of undoing all working directory changes including new files.

How to Revert All Working Dir Changes Including New Files in Git?

To undo all working directory changes including new files, follow the provided instructions:

Step 1: Switch to Git Repository

At first, execute the “cd” command with the particular repository path and move to it:

$ cd "C:\Users\nazma\Git\demo5"

Step 2: List Repository Content

Then, list the current repository content by utilizing the “ls” command:

$ ls

Step 3: View Git Reference Log History

Execute the “git log .” command to display the Git repository commit history:

$ git log .

Step 4: Generate File

Next, create a new text file with the help of the below-provided command:

$ touch file2.txt

Step 5: View Repository Status

After that, use the “git status .” command to check the Git current repository status:

$ git status .

As you can see in the provided output, the newly created “file2.txt” file has the untracked status:

Step 6: Undo Working Dir Changes

Finally, run the “git clean” command to revert the working directory changes:

$ git clean -f -d

Here, the “-f -d” option is used to remove the unwanted directories from the working directory forcefully:

Step 7: Verify Undo Changes

Lastly, check the status of the current working directory by executing the “git status .” command:

$ git status .

It can be seen that the working directory is clean, and there is nothing to commit:

We have provided the method to undo all working directory changes including new files.

Conclusion

To undo all working directory changes including new files, first, switch to the desired local repository and view the list of the repository content. Next, check the Git reference log history, generate a file, and check the current working repository status. Lastly, run the “git clean -f -d” command to undo all the working directory changes. This guide provided the procedure to undo all working directory changes including new files.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.