Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: What are the pros and cons of reset + force push vs revert

Tags:

git

What are the pros and cons of reset + force push vs revert. When each of those Technics appropriate?

This question is different from What's the difference between Git Revert, Checkout and Reset? because I want to know in more details about force push.

like image 483
Ilya Gazman Avatar asked Sep 09 '25 11:09

Ilya Gazman


1 Answers

Reset + force push

Pros: changes commit history which can be of help to clean up if you accidentally pushed a commit that should not have been pushed.

Cons: changes commit history which can screw up other developer's clone of the repo. If you force push something you will have to notify all other developers of what you did so they can take appropriate action to fix their local repo if needed. It is commonly advised to not do force pushes in teams with multiple developers. If you work alone however, this is of no concern and you can use it freely. Reset also erases the work from the history, meaning you probably will not be able to restore it later.

Revert

Pros: does not change commit history. Pros here are basically the opposite of the cons of reset + force push. Keeps the commit in history, should it ever need to be restored (you can revert a revert). Does not mess with other developer's clone of the repo.

Cons: any sensitive data commited will reside in your git history.

like image 199
Tim Avatar answered Sep 11 '25 06:09

Tim