DEV Community

Viktor Le
Viktor Le

Posted on

How to revert a committed & pushed file

If you've already committed the changes and want to revert the FooFile.php file to its original state without affecting other changes in your branch, you can follow these steps:

1. Identify the Commt:

First, identify the commit where the file was last in its desired state. You can use the following command to view the commit history for the file.

Note: the commit hash of the commit where the file was last correct.

git log -- FooFile.php
Enter fullscreen mode Exit fullscreen mode

2. Revert the File to a Specific Commit:

Use the following command to revert the file to the state it was in a specific commit:

git checkout <commit-hash> -- FooFile.php
Enter fullscreen mode Exit fullscreen mode

3. Commit the Reversion:

After reverting the file, you need to commit this change to your branch:

git add FooFile.php
git commit -m "Revert FooFile.php to its original state"
Enter fullscreen mode Exit fullscreen mode

4. Push the Changes:

Finally, push the changes to your remote repository:

git push
Enter fullscreen mode Exit fullscreen mode

Top comments (0)