'How to reset a project back to earlier code and overwrite existing changes on the local repo
Scenario: I have added a block of code, and it has caused all backgrounds for all button elements on my site to turn green. I am not happy with the method used, and wish to remove the code completely so I can start from before this change was applied on this branch, and implement a better way of targeting the buttons, using another approach on the same branch (backtrack).
Solution 1:[1]
wish to remove the code completely
To backtrack, you have two choices. First, find (using git log) the SHA of the commit you want to backtrack to, i.e. the last "good" commit before the "bad" commits started. Then either
git reset --hard <SHA>
or
git revert <SHA>..HEAD
The difference is that reset rewrites history and throws away the subsequent commits, while revert keeps the history and introduces new "undo" commits.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
