π How to revert (restore) only one file to specific commit (SHA)?
Problem
1) Currently I have git repository with green fruits image (could be any file type), where I earlier added a several changes andΒ commit and push them to the server:
But then, I realize, that I don't need that changes (green fruits) and I have the previous version, that I need (yellow fruits) in git repository history.
So, how to properly get only one specific old file revision without changing another files in the repository? ?
β‘ Resolution
So, you need to find commit where your file revision was that you want (not a commit with last changes of this file), you can do this by right-click in repository folder, press Git Bash Here, and to show full history type and enter:
git log --oneline
You can do this by look at the history of the specific file (in my case it's .png image, that placed in Images folder (see the explorer)):
But also consider the more convenient method do it using git client, such as GitHub Desktop, because of good diffs viewer:
Anyway, I have only two SHA (revisions) of the my file (plant.png), so current is:
- bcbf259
And I just need a previous:
- 1cba3eb
Firstly, I check my repository status and it's clean:
git status
And now I switch only one specific file (plant.png) to the specific revision:
git checkout 1cba3eb Images/plant.png
By checking status (git status) you can see, that only one file changed:
Now you can work with restored version, or right now commit it and push to the server.
If you want hear to return everything as it wasΒ (green fruits), just type (should be before commits; the dot means all):
git restore .
Conclusions
![]() | If you use cloud service, like Google Drive, it always upload the new saved version of file, so you could have tens of savings, that hard to figure out which one is significant. In git VSCΒ you manually set the REVISIONS, so later it could be easy to find the required REVISION. git checkout typically uses to switch all repo files to the specific commit, but, as we can see, it's not problem to switch only one chosen file to the specific commitΒ ?? |
![]() | βͺRECOMMENDATION:
π‘οΈ Get temperature from STM32 internal temperature sensor (simple library) |
- Comments