2

Suppose my last commit includes 6 files A, B, C, D, E, F. Now I only want to revert changes of only file B.

I have committed my whole project in git. My commit id is 41e6150. There are many files in my commit after the last commit but I want to only revert changes of specific file say X. how can I do that?

Son Truong
  • 13,661
  • 5
  • 32
  • 58
umair_aziz
  • 51
  • 1
  • 7
  • 1
    Possible duplicate of [Hard reset of a single file](https://stackoverflow.com/questions/7147270/hard-reset-of-a-single-file) – kowsky Aug 24 '18 at 07:43
  • 4
    Possible duplicate of [Reset or revert a specific file to a specific revision using Git?](https://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git) – stasiaks Aug 24 '18 at 07:44

1 Answers1

3

Probably your best option is to checkout the old version of that file and then create a new commit:

Suppose your old commit was 1a2b3c:

git checkout 1a2b3c -- fileX

Now you have a new status where all files are up to date but fileX is as it was at 1a2b3c. Just create a new commit and you've done.

ErniBrown
  • 1,283
  • 12
  • 25
  • kindly need bit more help . how to make new commit .? – umair_aziz Aug 24 '18 at 08:14
  • 1
    Well, that's basic git... anyway `git add fileX`, then `git commit -m "commit message here"` – ErniBrown Aug 24 '18 at 08:56
  • and also git push command after git commit -m "commit message here" or not ? – umair_aziz Aug 24 '18 at 09:14
  • Do so if you want to publish everything on a server... Anyway I think you really need to follow some kind of guide, such as this one: https://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide – ErniBrown Aug 24 '18 at 09:18