0

How to revert specified file to before version? for examples:( the next line is latter time )

commitIDa create main.go and other operations
commitIDb modify main.go to content1 and other operations
...... (may be a lot of logs)
commitIDc modify main.go to content2 and other operations
commitIDd ??????(my demand is following:)

Now,I want the file main.go content to revert commitIDb ,and its log is only :

commitIDa
commitIDb

except for file main.go, other operations files may have the logs following:

commitIDa
commitIDb
...
commitIDc
commitIDd

In other words,I want to delete main.go log information from (...) and commitIDc

Then I can git push to the remote origin

reset-or-revert-a-specific-file-to-a-specific-revision-using-git could not works.And my question is different frrom it. Because it will commit new commitID, and its content is same with the before one.

The core difference of my question is : main.go logs is only commitIDa commitIDb ,no new commitID to be commited. In the other words, it delete about main.go logs from the logs which is after commitIDb

Jim Green
  • 1,088
  • 3
  • 15
  • 40
  • 3
    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) – Thibault D. Apr 01 '18 at 07:57
  • What do you mean by "This did not work?" what have you tried and what did you get? – Thibault D. Apr 01 '18 at 07:58
  • From my test, the file main.go still have ... and commitIDc logs,I hope its logs only commitIDa commitIDb – Jim Green Apr 01 '18 at 08:00
  • git checkout HEAD~2 -- main.go , git log , It still as usual – Jim Green Apr 01 '18 at 08:03
  • 1
    You cannot change the history of one file only. A commit includes all the files of the project (that were tracked when the commit was created). In order to remove some commits from the history of a file you have to rewrite the history and change those commits to not change the file. It is not difficult but if the current history has already been pushed, it is not recommended to change the history; it will confuse the other people that work on the project. – axiac Apr 01 '18 at 08:17
  • You made a really good point. But does the git support this operation now? Could you provide the solution ? Now I wanna changed my created branch about this point. – Jim Green Apr 01 '18 at 08:22
  • read the git book, and especially the parts about git rebase. – JB Nizet Apr 01 '18 at 08:25
  • rebase could not help me, it will affect other files' logs – Jim Green Apr 01 '18 at 08:34
  • @Thibault D, Dear !my question really different from [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) – Jim Green Apr 02 '18 at 11:13
  • You cannot do what you are asking for – sensorario Apr 02 '18 at 17:10

0 Answers0