How does 'git revert' differ from 'git reset'?

0208

git revert and git reset serve different purposes in Git:

git revert

  • Non-Destructive History: It creates a new commit that undoes the changes made by a previous commit, preserving the history.
  • Safe for Collaboration: Since it doesn't rewrite history, it's safe to use in shared repositories. Other collaborators can see both the original commit and the revert.
  • No Force Push Required: You can push the revert without needing to force push, which avoids disrupting others' work.

git reset

  • Rewrites History: It changes the commit history by moving the current branch pointer to a specified commit, effectively removing commits from the history.
  • Potentially Disruptive: If you've already pushed commits, using git reset often requires a force push (git push --force), which can overwrite others' work.
  • Use with Caution: It's generally used for local changes or when you want to completely remove commits from the history.

In summary, use git revert for safe collaboration and maintaining history, while git reset is more suited for local changes where history rewriting is acceptable.

0 Comments

no data
Be the first to share your comment!