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 fi…


This content originally appeared on DEV Community and was authored by Viktor Le

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

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

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"

4. Push the Changes:

Finally, push the changes to your remote repository:

git push


This content originally appeared on DEV Community and was authored by Viktor Le


Print Share Comment Cite Upload Translate Updates
APA

Viktor Le | Sciencx (2025-09-09T02:16:39+00:00) How to revert a committed & pushed file. Retrieved from https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/

MLA
" » How to revert a committed & pushed file." Viktor Le | Sciencx - Tuesday September 9, 2025, https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/
HARVARD
Viktor Le | Sciencx Tuesday September 9, 2025 » How to revert a committed & pushed file., viewed ,<https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/>
VANCOUVER
Viktor Le | Sciencx - » How to revert a committed & pushed file. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/
CHICAGO
" » How to revert a committed & pushed file." Viktor Le | Sciencx - Accessed . https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/
IEEE
" » How to revert a committed & pushed file." Viktor Le | Sciencx [Online]. Available: https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/. [Accessed: ]
rf:citation
» How to revert a committed & pushed file | Viktor Le | Sciencx | https://www.scien.cx/2025/09/09/how-to-revert-a-committed-pushed-file/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.