4/3/2023 0 Comments Git revertGit revert requires the id of the commit you want to remove keeping it into your history The question is quite old but revert is still confusing people (like me)Īs a beginner, after some trial and error (more errors than trials) I've got an important point: Indeed - if the remote is in an unstable state - communicating to the rest of the team that they need to pull to get the fix (the reverting commit) would be the right thing to do :). Obviously you'll need to push again and probably announce to the team. Git revert is a commit - there are no extra steps assuming reverting a single commit is what you wanted to do. push to the remote so that other users can pull/fetch/merge the changes and you're done.ĭo you have to commit the changes revert made or does revert directly commit to the repo? Closing questionsĪ git revert is just another commit, so e.g. It doesn't matter where in the history the commit to be reverted is (in the above example, the last commit is reverted - any commit can be reverted). So there is a consistent history of what has happened, yet the files are as if the bad update never occured: cat README.md There will be 3 commits in the log: $ git log -oneline In this example the commit history has two commits and the last one is a mistake. initial commitġ file changed, 1 insertion(+), 1 deletion(-) Initialized empty Git repository in /tmp/example/.git/ For example, consider the following simple example: $ cd /tmp/example It leaves the files in the same state as if the commit that has been reverted never existed. Git revert simply creates a new commit that is the opposite of an existing commit. Obviously, you'll need to push again and probably announce your balls-up to the team. Okay, you're going to use git revert, but how?Īnd after running git revert, do you have to do something else after? Do you have to commit the changes revert made or does revert directly commit to the repository or what? This is what source control is all about. It’s not something you can hand-undo in code yourself, say some wizard or package manager changed tons of stuff all over the place - you just want to put it all back how it was. You've pushed and other people have your bad changes. So let’s try and stick the brief and write a Dummies Guide to git revert.Ī scenario: you've committed twice to master and it’s bad. Then when someone asks how to use git reset people reply saying you should use git revert as per Git - how to rollback.īefore you know it, eight different people appeared with their own unique ways to save the OP's ass, all of which is over your head. This might sound like a duplicate question but when people ask it, the response is often, use git reset as per Revert to a commit by a SHA hash in Git?.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |