Think Like a Git, Commit Like a Boss: Revert Now!
The “revert” feature solves a different problem: You might have one particular commit that you want to undo – but you don’t want to touch any other commits that came after it.
Revert solves this problem by creating a new commit that contains opposite changes – essentially reverting the effect of those changes. E.g. if you deleted some lines in a certain commit, reverting it will create a new commit that adds exactly these lines back.
Now for our project git-education:
Let’s revert our last commit like so:
git revert eb945247d758529843bc25ffa347d794707d4111
Note: eb945247d758529843bc25ffa347d794707d4111 refers to the commit hash of the most recent commit in the git history.
Now, go ahead and check the notes.txt file, You’ll discover it removes the last change. Now run git log to check the history:
Dang!!, the history still remains unchanged!. So the difference between Reset and Revert is this:
1.Revert doesn’t change the project history, which makes it safe for commits that have already been published to a shared repository. Reset alters the history.
2. Revert only undo changes in a particular commit that was referenced at any point in the git history. Meanwhile, Reset removes all the commit that occurred after the commit that is been referenced currently.
So, when you are working on a project with other developers. It’s always advisable not to alter the git history at all. You will be considered Evil if you delete the history at any point unless it’s absolutely necessary. The git history is always necessary to track down the activities of several developers on a project and also easily track down the time a bug was introduced into the project.
Please, Let me know if you have any questions in the comment section. Stay tuned for More!
- How to build your own Youtube – Part 10 - August 1, 2016
- How to build your own Youtube – Part 9 - July 25, 2016
- How to build your own Youtube – Part 8 - July 23, 2016
- How to build your own Youtube – Part 6 - July 6, 2016
- Introducing Laravel Password v1.0 - July 3, 2016
- How to build your own Youtube – Part 5 - June 28, 2016
- How to build your own Youtube – Part 4 - June 23, 2016
- How to build your own Youtube – Part 3 - June 15, 2016
- How to build your own Youtube – Part 2 - June 8, 2016
- How to build your own Youtube – Part 1 - June 1, 2016