Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git revert just some files in commit [duplicate]

Tags:

I have few commits on github that I want to change. So in my previous commit I've changed some file/folders and I need to revert changes only for some of them. What is the best solution to make it.

like image 827
Matrosov Oleksandr Avatar asked Mar 24 '16 13:03

Matrosov Oleksandr


People also ask

How do I revert to a previous version of a file in git?

To move HEAD around in your own Git timeline, use the git checkout command. There are two ways to use the git checkout command. A common use is to restore a file from a previous commit, and you can also rewind your entire tape reel and go in an entirely different direction.


1 Answers

You can use git checkout:

git checkout HEAD~ -- file/to/revert 

to stage a version of the file from the previous commit. Then just commit the changes and you're good to go! Of course, you can replace HEAD~, which references the previous commit, with a hash of a commit, a further-back ancestor, or any "tree-ish" object you wish.

like image 157
JKillian Avatar answered Oct 31 '22 14:10

JKillian