Issue
As a git novice, I need to revert my app to a previous version from 2 commits ago. I am unsure how to do this and also want to know if it is possible to delete the "bad" commits or create a new branch from the "good" commit. I need some guidance to accomplish this.
Resolution
To revert your Git repository to a previous commit, you can use the git revert
or git reset
commands. Here’s how you can do it:
Option 1: Revert the commits
- Open up your terminal and navigate to the directory where your app is located. Use
git log
to view the commit history and find the commit hash of the “good” commit. - Use
git revert <commit hash>
to revert the commits. This will create a new commit that is the opposite of the reverted commits. - Push the changes to the remote repository.
Option 2: Reset to the previous commit and create a new branch
- Open up your terminal and navigate to the directory where your app is located. Use
git log
to view the commit history and find the commit hash of the “good” commit. - Use
git reset --hard <commit hash>
to reset the repository to the previous commit. This will discard any changes made after the “good” commit. - Use
git checkout -b <new branch name>
to create a new branch with the reset state. - Push the new branch to the remote repository.
Note that these operations will permanently remove the commits you’ve deleted from the branch. If you want to keep a record of the deleted commits, you can create a new branch containing those commits before performing the deletion.
Option 3: Revert the changes using the GUI
For an easy GUI way of doing this, you can clone the Appsmith repository into GitHub Desktop and revert the changes as shown in the GitHub docs.