I’m a git novice, and I would like to revert my app to a version from 2 commits ago. I have been able to successfully import an app from git (when I accidentally deleted the app on Appsmith), but only know how to do an import on the current version. Ideally I’d like to delete the two most recent “bad” commits, but am also happy to create a new branch at the last “good” commit. Can you give me some guidance on how to do this?
Hello Dan!
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.
Thank you for such a fast response! I just did three git reverts, but used GitHub Desktop to avoid dealing with connecting to git via terminal (in the spirit of low code).
In the future, if anyone else has the same question, the easy GUI way of doing this is to cloning your Appsmith repository into GitHub Desktop (assuming you’re using GitHub) and reverting as shown here.