This write-up will elaborate on the procedure to undo the removing file operation(undo rm) in the Git directory.
How to Undo rm in Git?
To understand undo rm in Git, first, we will create a file and add it to the Git repository from the working area to the staging area. Then, commit changes, and remove the file from the directory utilizing the “$ git rm” command. After that, undo rm actions.
Let’s move toward the procedure!
Step 1: Launch Git Terminal
Launch the Git terminal using the “Startup” menu:
Step 2: Navigate to Folder
Next, move to the “Git” folder utilizing the “cd” command:
Step 3: Create New Git Directory
Execute the “mkdir” command to create a new directory:
Step 4: Move to Git Directory
Move to the newly created directory:
Step 5: Create File
Now, create a new file using the “touch” command:
Step 6: Add File
Add the newly created file to the Git directory to track from the working directory to the staging area:
Step 7: Commit Changes
Save commit changes to the directory using the “git commit” command:
Step 8: Remove File
Utilize the “git rm” command to remove the file named “file” from Git index:
As you can see, the file removed successfully from “Linux_hint” directory:
Step 9: Undo rm
After removing the file, revert it back with the help of the following command:
Here, the “file” is reverted successfully:
Step 10: Restore File
Run the “git checkout” command to reset the deleted file from the last check-in in the same repository:
We have illustrated the procedure to undo the removing file operation in the Git directory.
Conclusion
To undo rm in the Git repository, first, open the Git terminal. Move to the Git folder, create a new Git directory and add a new file. Then, add the file to track from the working area to the staging area. Next, commit changes to the Git repository. Now, delete the file from the repository and run the “$ git reset” command to undo rm. Lastly, run the “$ git checkout <file>” to restore the removed file from the last check-in. This write-up demonstrated the easiest way to undo rm in Git.