loading...

re: How to undo the last commit VIEW POST

TOP OF THREAD FULL DISCUSSION
re: For a quick revert you can use git reset HEAD^1 --hard and the you can commit it with additional changes. I thing this "prevents" the revert prefix...
 

As long as the commit you are 'undoing' is local and is not part of any remote branch (you have not push-ed it yet), or if this is a one-dev pet project and you are sure nobody is 'consuming' your remote branch (and you can push to it with --force) - git reset is OK.

The thing is - it rewrites history. So if you'll make another commit on top of it but the 'undone' commit is pushed already, the history of your local branch and your remote tracking branch will diverge - and you'd have to push it either to another branch, or with --force, rewriting the remote branch. And if the remote branch is rewritten, anyone who had cloned it won't be able to pull from it any more that easily etc...

Thus the general advise is not to rewrite history of remote branches, and that's what git revert is for.

Funny side note - once seen a commit starting with a word Revert repeated 6 times o_O

 

Great explanation! In my case, I thought revert was better because I pushed the previous changes before.

code of conduct - report abuse