1. Git Revert

4763b539-09b9-444b-9dd2-6262114164c3.avif

Imagine you've made a mistake in a commit and want to undo it without losing history. Instead of deleting the commit, git revert creates a new commit that reverses the changes of the previous one. This way, your history stays intact while your files return to their previous state.

Key Differences Between Git Reset and Git Revert

How Git Revert Works

  1. Identify the commit you want to revert using git log --oneline.
  2. Run git revert <commit-id>.
  3. Git will create a new commit that cancels out the changes from the specified commit.
  4. This process maintains version history, making it safer for collaborative projects.

2. Removing Untracked Files

Sometimes, your working directory has untracked files (files not added to Git). If you want to remove them without affecting tracked files, you can use git clean.

Commands to Remove Untracked Files

⚠️ Be cautious when using git clean -f, as it permanently deletes files!